zoukankan      html  css  js  c++  java
  • (周日赛)Winner

    题意:#转 

    /*玩一个游戏,每轮有一个人得分,或减分,当所有轮完成后,找出分数最高的那个人,
    如果是多个人,找出那些人中第一个达到最高分或更高的人。

    先保存好每个人的分数,记录下究竟有那几个人会得奖,再次遍历所有回合,
    找出第一个高于等于那个分数的且最终会得奖的人。
    */

    Sample Input

    Input
    3
    mike 3
    andrew 5
    mike 2
    Output
    andrew
    Input
    3
    andrew 3
    andrew 2
    mike 5
    Output
    andrew
     
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 struct point
     7 {
     8     char name[20];
     9     int num;
    10 }a[1000],b[1000];
    11 char s[1000][35];
    12 int x[1000];
    13 
    14 int main()
    15 {
    16     int n,i,j;
    17     while(~scanf("%d",&n))
    18     {
    19         int d=0;
    20         memset(a,0,sizeof(a));
    21         for(i=0;i<n;i++)
    22         {
    23             scanf("%s %d",s[i],&x[i]);
    24             if(d)
    25             {
    26                 for(j=0;j<d;j++)
    27                     if(!strcmp(a[j].name,s[i]))
    28                     {
    29                         a[j].num+=x[i];
    30                         break;
    31                     }
    32                 if(j==d)
    33                 {
    34                     strcpy(a[d].name,s[i]);
    35                     a[d++].num=x[i];
    36                 }
    37             }
    38             else
    39             {
    40                 strcpy(a[0].name,s[i]);
    41                 a[0].num=x[i];
    42                 d++;
    43             }
    44         }
    45         int maxn=0;
    46         for(i=0;i<d;i++)
    47             maxn=max(maxn,a[i].num);
    48         memset(b,0,sizeof(b));
    49         int dd=0;
    50         for(i=0;i<n;i++)
    51         {
    52             if(dd)
    53             {
    54                 for(j=0;j<dd;j++)
    55                     if(!strcmp(b[j].name,s[i]))
    56                     {
    57                         b[j].num+=x[i];
    58                         if(b[j].num>=maxn&&a[j].num==maxn)
    59                         {
    60                             printf("%s
    ",s[i]);
    61                             return 0;
    62                         }
    63                         break;
    64                     }
    65                     if(j==dd)
    66                     {
    67                         strcpy(b[dd].name,s[i]);
    68                         b[dd].num=x[i];
    69                         if(b[dd].num>=maxn&&a[dd].num==maxn)
    70                         {
    71                             printf("%s
    ",s[i]);
    72                             return 0;
    73                         }
    74                         dd++;
    75                     }
    76             }
    77             else
    78             {
    79                 strcpy(b[0].name,s[i]);
    80                 b[0].num=x[i];
    81                 if(x[i]>=maxn&&a[0].num==maxn)
    82                 {
    83                     printf("%s
    ",s[i]);
    84                     return 0;
    85                 }
    86                 dd++;
    87             }
    88         }
    89     }
    90     return 0;
    91 }
  • 相关阅读:
    centos 7 有点意思
    Thinkphp中路由Url获取的使用方法
    smarty中的母板极制_extends和block标签
    linux下php多版本的并存实现
    centos nginx,php添加到Service
    CI_Autocomplete_2.0.php轻松实现Bebeans与Codeigniter的智能提示
    php中的性能挖掘
    tar命令,转来等用
    Smarty插件简单开发
    iOS 7用户界面过渡指南
  • 原文地址:https://www.cnblogs.com/awsent/p/4281647.html
Copyright © 2011-2022 走看看