PTA乙级题 1064. 朋友数(20)
#include<stdio.h>
int main()
{
int i,j,n,s,temp,x=1;
scanf("%d",&n);
int a[n]={0},b[n]={0},c[n]={0};
for (i=0;i<n;i++)
scanf("%d",&a[i]);
for (i=0;i<n;i++)
{
b[i]=0;
while (a[i])
{
s=a[i]%10;
b[i]+=s;
a[i]/=10;
}
}
for (i=0;i<n-1;i++)
{
for (j=0;j<n-i-1;j++)
{
if (b[j]>b[j+1])
{
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
c[0]=b[0];
for (i=1;i<n;i++)
{
if (b[i]!=b[i-1])
{
c[x]=b[i];
x++;
}
}
printf("%d\n",x);
printf("%d",c[0]);
for (i=1;i<x;i++)
printf(" %d",c[i]);
return 0;
}