PAT乙级1004 成绩排名
Posted eurusliu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT乙级1004 成绩排名相关的知识,希望对你有一定的参考价值。
我的解法(提示格式错误)
#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
",a[max_index]);
printf("%s
",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
%s %s", maxname, maxid, minname, minid);
return 0;
}
以上是关于PAT乙级1004 成绩排名的主要内容,如果未能解决你的问题,请参考以下文章