【PAT】B1064 朋友数(20 分)

以前写的,逻辑不好,过后再改

#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
bool cmp(int a,int b){
    return a<b;
}
int zhenghao(int a){
    return a%10+a%100/10+a%1000/100+a/1000;
}
bool youmeiyou(int *arr,int a,int flag){
    int temp=zhenghao(a);
    for(int i=0;i<flag;i++){
        if(arr[i]==temp){return 1;}
    }
    return 0;
}
int main(){
    //个数
    int N;
    scanf("%d",&N);
    int arr[N];
    int pengyouhao[100010],flag=0;
    for(int i=0;i<N;i++){
         scanf("%d",&arr[i]);
        if(!youmeiyou(pengyouhao,arr[i],flag)){//如果没有
            pengyouhao[flag++]=zhenghao(arr[i]);
        }
    }
    sort(pengyouhao,pengyouhao+flag,cmp);
    printf("%d\n",flag);
    for(int i=0;i<flag;i++){
        if(i!=0)printf(" ");
        printf("%d",pengyouhao[i]);
    }
    return  0;
}
全部评论

相关推荐

小肥罗:此乃引蛇出洞之计,勾出你想去杭州的原因再告诉你不在杭州,让你打脸,自己离开。好一招抛砖引玉,虾仁猪心。你回复:计划去杭州,但我心中第一选择是宁波~巧了! 这计名叫“阿Q精神胜利法之厚脸皮不要脸我不尴尬谁爱尴尬谁尴尬去”之计!克制一切!
这个工作能去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务