我的解法(提示格式错误)
#include <stdio.h>
int main()
{
int n, i,min,max,min_index,max_index;
scanf("%d",&n);
char c = getchar();
//char* a[1000];
char a[1000][30];
int b[1000];
for(i=0;i<n;i++)
{
int space = 0,j=0;
char ch;
while(space<=1)
{
ch = getchar();
if(ch == ' ') space++;
a[i][j++] = ch;
}
scanf("%d",&b[i]);
char ll = getchar();
if(i==0)
{
min = b[i];
min_index =i;
max = b[i];
max_index =i;
}
if (b[i]>max)
{
max = b[i];
max_index =i;
}
if (b[i]<min)
{
min = b[i];
min_index =i;
}
}
printf("%s\n",a[max_index]);
printf("%s\n",a[min_index]);
}
博客解法:
#include <stdio.h>
#include <string.h>
int main()
{
int N;
scanf("%d", &N);
char maxname[11], minname[11], curname[11],
maxid[11], minid[11], curid[11];
int maxgrade = -1, mingrade = 101, curgrade;
for(int i = 0; i < N; i++)
{
scanf("%s %s %d", curname, curid, &curgrade);
if(curgrade > maxgrade)
{
strcpy(maxname, curname);
strcpy(maxid, curid);
maxgrade = curgrade;
}
if(curgrade < mingrade)
{
strcpy(minname, curname);
strcpy(minid, curid);
mingrade = curgrade;
}
}
printf("%s %s\n%s %s", maxname, maxid, minname, minid);
return 0;
}
原文地址:https://www.cnblogs.com/EurusLIU/p/11762158.html
时间: 2024-11-08 22:50:21