hdu 2412 (disney) 模拟、字符串处理

 disney

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 583    Accepted Submission(s): 146


Problem Description
  A new machine was introduced into disney world. Every day, there is a long queue because of its function. Everyone can input their score or update their score. If you want to know the maximum or the average, it can help you, too.What's more, if you don't want that your score be saw, you can delete your register from it. Since the new machine was introduced, everyone be more hard.
 

 

Input
The input contain only one case. 
There are kinds of format that show different functions:
(1)NEW name score(you can use it to input your score or update your score)
name: the name of current user.The length of the name is no longer than 8.
score: the score of current user.(0<score<=100)
(2)AVERAGE(you can use is to get the average score)
(3)MAX(you can use is to get the maximal score and whose score is the maximum.)
(4)DELETE name:delete the name and its record too.
name: the name of current user.The length of the name is no longer than 8.
(5)QUIT(this command is used to turn off the machine,is the end of the input)
 

 

Output
(1)For "NEW name score" , if it's there is a lack of record of the user. print "A new record".else print "update succeed".
(2)For "AVERAGE" , you should print the average score rounded to two digits after the decimal point.if there are none record in the machine,the average is 0.00;
(3)For "MAX" , you should first print the maximal score and the number that whose score is the maximum, then print all of their names Lexicographicly, and each name owns a single line. If there isn't any record in the machine,just output"0 0".
(4)For "DELETE name" , if there is a lack of record of the user. print "no such record".else print "delete succeed".

The population of disney is no more than 100.
 
Sample Input
NEW mickey 99
NEW mini 88
MAX
AVERAGE
ELETE winnie QUIT
 
 
Sample Output
A new record
A new record
99 1
mickey
93.50
no such record
 
Source
 
 
好吧!这一题是我想多了,刚开始以为,如果是同一个人的话,第二次的成绩没有上一次高的话会更新吗!(我还联系上现实了)
还有,统计平均成绩时,已经清除成绩该记录吗!。。。。。。     吓得我不敢写了。。。
好吧!就吸取经验,就严格按题目上的来,不要想太多。。。@_@
注意的地方:同一个人第二次的成绩无论有没有第一次的成绩高,都要更新!意味着对于同一个人新的成绩要把旧的成绩覆盖掉,旧的成绩就当没出现过,所以这样被覆盖掉的成绩就不参与平均成绩与最大成绩的计算了。明白了这一点就能写出正确的程序。
 

    

  1 #include<iostream>
  2 #include<cstring>
  3 #include<cstdio>
  4 #include<algorithm>
  5 using namespace std;
  6 #define N 150
  7 struct node{
  8     char name[10];
  9     int score;
 10     int flag;
 11 }s[N];
 12 struct m_name{
 13     char name[10];
 14 }s2[N];
 15 bool cmp(m_name a,m_name b)
 16 {
 17     return strcmp(a.name,b.name)<0;
 18 }
 19 int big=0;
 20 double average;
 21 double sum=0;
 22 int p=0;
 23 int main()
 24 {
 25     char str[50];
 26     memset(s,0,sizeof(s));
 27     memset(s2,0,sizeof(s2));
 28     int i=0;
 29     int j;
 30     while(gets(str))
 31     {
 32         if(strcmp(str,"QUIT")==0)  break;
 33         int k;
 34         char ss1[10],ss2[10];
 35         int mark;
 36         k=sscanf(str,"%s %s %d",ss1,ss2,&mark);
 37         if(k==3)
 38         {
 39             for(j=0;j<i;j++)
 40             {
 41                 if(strcmp(s[j].name,ss2)==0&&s[j].flag)//特别注意这个地方 因为是按照名字检索的然而有的人已经被删除(所以flag代表未被删除的人)
 42                 {//这个地方wa了  由于没加s[j].flag
 43                     printf("update succeed\n");
 44                     sum-=s[j].score;
 45                     sum+=mark;
 46                     s[j].score=mark;
 47                     break;
 48                 }
 49             }
 50                 if(j==i)
 51                 {
 52                     printf("A new record\n");
 53                     strcpy(s[i].name,ss2);
 54                     sum+=mark;
 55                     s[i].score=mark;
 56                     s[i].flag=1;
 57                     i++;
 58                     p++;
 59                 }
 60             
 61         }
 62         if(k==2)
 63         {
 64             for(j=0;j<i;j++)
 65             {
 66                 if(strcmp(s[j].name,ss2)==0&&s[j].flag)//同上
 67                 {
 68                     printf("delete succeed\n");
 69                     s[j].flag=0;
 70                     sum-=s[j].score;
 71                     p--;
 72                     break;
 73                 }
 74             }
 75             if(j==i)
 76             {
 77                 printf("no such record\n");
 78             }
 79         }
 80         if(strcmp(str,"AVERAGE")==0)
 81         {
 82             if(p)
 83                 printf("%.2lf\n",sum/p);
 84             else
 85                 printf("0.00\n");
 86         }
 87         if(strcmp(str,"MAX")==0)
 88         {
 89             big=0;
 90             for(j=0;j<i;j++)
 91             {
 92                 if(s[j].score>big&&s[j].flag)
 93                 {
 94                     big=s[j].score;
 95                 }
 96             }
 97             if(big==0)
 98                 printf("0 0\n");
 99             else
100             {
101                 int kk=0;
102                 for(j=0;j<i;j++)
103                 {
104                     if(s[j].score==big&&s[j].flag)
105                     {
106                         strcpy(s2[kk++].name,s[j].name);
107                     }
108                 }
109                 printf("%d %d\n",big,kk);
110                 sort(s2,s2+kk,cmp);
111                 for(j=0;j<kk;j++)
112                 {
113                     printf("%s\n",s2[j].name);
114                 }
115 
116             }
117         }
118     }
119     return 0;
120 }
121 
122                 
123 
124                     
125         

 

     
  

 

转载于:https://www.cnblogs.com/heat-man/archive/2013/04/22/3034940.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值