标签:提高 使用 blog 声明 har main log str class
//结构体的使用是这个题的提高之处
#include<cstdio>
struct Student//结构体的定义格式写法是?结构体对象的声明呢?typedef需要吗?
{
char name[12];
char id[12];
int score;
}temp,max,min;//结构体对象的的声明;
int main()
{
int n;
max.score = 0;//出错点:最值的设立,为了将临时数据的存储和更新
min.score = 100;
scanf("%d", &n);
while (n--)
{
scanf("%s%s%d", temp.name, temp.id, &temp.score);//注意区别,给结构体里数组名不用&
if (temp.score >= max.score)
max = temp;//结构的整个数据交换也是可以的!!!
if (temp.score <= min.score)
min = temp;
}
printf("%s %s\n",max.name, max.id);
printf("%s %s\n", min.name, min.id);
return 0;
}
标签:提高 使用 blog 声明 har main log str class
原文地址:http://www.cnblogs.com/dusanlang/p/7453517.html