全班都进前50的屑 • 2年前
求思路!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
评论:
int main() {
int a[100000],n,i,j,k=0,t,x,c=1,y;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for (int j = 1; j <= n - 1; j++) {
for (int i = 0; i <= n - 1 - j; i++) {
if (a[i] >= a[i + 1]) {
x = a[i];
y = a[i + 1];
a[i] = y;
a[i + 1] = x;
}
}
}
for(i=0;i<n-1;i++)
{
t=a[i];
for(j=i+1;j<n;j++)
{
if(t==a[j])
{
c++;
}
}
printf("%d %d\n",t,c);
}
return 0;
}
输入 12 9 1400000000 3 89 5645897 6 897456322 8 8 1500000000 90 89 输出 3 1 6 1 8 2 8 2 9 2 89 3 89 3 90 3 5645897 3 897456322 3 1400000000 3 答案 3 1 6 1 8 2 9 1 89 2 90 1 5645897 1 897456322 1 1400000000 1 1500000000 1 系统信息 exit code: 0, checker exit code: 0
请先登录,才能进行评论