XTU OJ1328 数码和

#include
#include
/*
3
17
20
1000000000
*/ 
int b[20];
int c[10000];
typedef long long ll;
int main()
{
    int k;
    scanf("%d",&k);
    while(k--)
    {
        ll a,p;
        scanf("%lld",&a);
        for(int i=2;i<=16;i++){
            p=a;
            while(p)
            {
                b[i]+=p%i;
                p=p/i;                
            }
            c[b[i]]++;
        }
        int time=c[0];
        for(int i=1;i<=9999;i++){
            if(c[i]>time) time=c[i];    //找到出现次数最多为time; 
        }
        printf("%d\n",time);
//有可能出现次数会有重复    
        for(int i=0;i<=9999;i++){
            if(c[i]==time) 
            {
                printf("%d",i);    
                for(int j=2;j<=16;j++){
                    if(b[j]==i)    printf(" %d",j); 
                }
                printf("\n");
            }
        }
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
    }
    return 0;
} 

你可能感兴趣的:(湘大oj,c语言)