您的位置:首页 > 其它

Course(简单的字符串处理问题)

2014-11-29 21:34 316 查看
Course
时间限制:1000 ms | 内存限制:65535 KB
【问题描述】
There is such a policy in Sichuan University that if you are not satisfied with the score of your course, you can study this course again to get a better score. If you do this and get a higher score(than the highest score he got before), it can cover the original one. And we can say this time you update the score of this course successfully.

Here is one schoolmate's all the courses he has studied and scores he got (sorted by chronological order). So could you tell me how many time he successfully update his scores of courses?
【输入】
The first of input is an integer T which stands for the number of test cases. For each test case the first line is an integer N (1 <= N <= 100) which stands for the number of courses he has studied. Then following N lines, each line contains a string (only contains letters and the length is no more than 30,which stands for the course name) and an integer (0<=integer<=100, which stands for the score of the course),separated by a space.

Remember: the best way is getting the best score in one time.
Study one course many times is not a recommended choice!
【输出】
For each test case output the number of times he update successfully.
【样例输入】
2
6
CProgramming 70
DataStructrue 80
CProgramming 80
CProgramming 60
CProgramming 90
DataStructrue 70
2
CompilerTheory 95
Network 90
【样例输出】
2
0

一道很无脑的题,简单来说就是算出成绩突破次数。我还花了半个多小时,真是打脸啊。。。。

普通结构体写法:

#include<cstdio>
#include<cstring>
struct course
{
char name[35];
int score;
}p[105];
int main()
{
int i,j,m,n,count,num,sum;
char str[35];
scanf("%d",&n);
while(n--)
{
count=sum=0;
scanf("%d",&m);
for(i=0;i<m;i++)
{
int sign=1;
scanf("%s%d",str,&num);
for(j=0;j<count;j++)
if(!strcmp(p[j].name,str)&&num>p[j].score)
{p[j].score=num;sign=0;sum++;break;}
if(sign)
{strcpy(p[j].name,str);p[j].score=num;count++;}
}
printf("%d\n",sum);
}
return 0;
}


以此为鉴,下不为例。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: