【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;
}
全部评论

相关推荐

用微笑面对困难:这里面最强的是驾驶证了,可以入职美团大厂,然后直接开启黄马褂人生
点赞 评论 收藏
分享
用微笑面对困难:不是你千万别小看这家公司,他们的预估市值成倍上涨,三次在报告看见这个公司了,总之如果是给股权的话可以试试,未来没准真能发家致富哈哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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