superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ZOJ 1224 - Stats

Posted on 2008-06-03 09:53 superman 阅读(373) 评论(0)  编辑 收藏 引用 所属分类: ZOJ
  1 /* Accepted 1224 C++ 00:00.01 840K */
  2 #include <iostream>
  3 
  4 using namespace std;
  5 
  6 int main()
  7 {
  8     int n;
  9     int HIT[56= { 0 };
 10     int ERR[56= { 0 };
 11     int DIG[56= { 0 };
 12     int KILL[56= { 0 };
 13     int BLOCK[56= { 0 };
 14     int GAMES[56= { 0 };
 15      
 16     char key;
 17     int GameCount = 0;
 18     int CurrentPlayerNumber;
 19     while(cin >> key)
 20     {
 21         if(key == 'C')
 22         {
 23             cin >> n;
 24             for(int i = 0; i < n; i++)
 25             {
 26                 cin >> CurrentPlayerNumber;
 27                 GAMES[CurrentPlayerNumber]++;
 28             }
 29             GameCount++;
 30             continue;
 31         }
 32         if(key == 'H')
 33         {
 34             cin >> CurrentPlayerNumber;
 35             HIT[CurrentPlayerNumber]++;
 36             continue;
 37         }
 38         if(key == 'K')
 39         {
 40             cin >> CurrentPlayerNumber;
 41             KILL[CurrentPlayerNumber]++;
 42             continue;
 43         }
 44         if(key == 'E')
 45         {
 46             cin >> CurrentPlayerNumber;
 47             ERR[CurrentPlayerNumber]++;
 48             continue;
 49         }
 50         if(key == 'B')
 51         {
 52             cin >> CurrentPlayerNumber;
 53             BLOCK[CurrentPlayerNumber]++;
 54             continue;
 55         }
 56         if(key == 'D')
 57         {
 58             cin >> CurrentPlayerNumber;
 59             DIG[CurrentPlayerNumber]++;
 60             continue;
 61         }
 62         //key == 'R'
 63         cout << "Player  Hit Pct    KPG      BPG      DPG" << endl;
 64         cout << "-----------------------------------------" << endl;
 65         
 66         for(int i = 0; i <= 55; i++)
 67             if(GAMES[i])
 68             {
 69                 double HitPct = 0.0;
 70                 if(KILL[i] + ERR[i] + HIT[i])
 71                     HitPct = double(KILL[i] - ERR[i]) / (KILL[i] + ERR[i] + HIT[i]);
 72                 double KPG = double(KILL[i]) / GAMES[i];
 73                 double BPG = double(BLOCK[i]) / GAMES[i];
 74                 double DPG = double(DIG[i]) / GAMES[i];
 75                 
 76                 printf("%02d      %+5.3f  % 7.3f  % 7.3f  % 7.3f", i, HitPct, KPG, BPG, DPG); 
 77                 cout << endl;
 78             }
 79         
 80         int SumBLOCK = 0;
 81         int SumKILL = 0;
 82         int SumERR = 0
 83         int SumDIG = 0;
 84         int SumHIT = 0;
 85         
 86         for(int i = 0; i <= 55; i++)
 87             if(GAMES[i])
 88             {
 89                 SumBLOCK += BLOCK[i];
 90                 SumKILL += KILL[i];
 91                 SumERR += ERR[i];
 92                 SumDIG += DIG[i];
 93                 SumHIT += HIT[i];
 94             }
 95         double HitPct = 0.0;
 96         if(SumKILL + SumERR + SumHIT)
 97             HitPct = double(SumKILL - SumERR) / (SumKILL + SumERR + SumHIT);
 98         double KPG = double(SumKILL) / GameCount;
 99         double BPG = double(SumBLOCK) / GameCount;
100         double DPG = double(SumDIG) / GameCount;
101         
102         printf("team    %+5.3f  % 7.3f  % 7.3f  % 7.3f", HitPct, KPG, BPG, DPG); 
103         cout << endl << endl; 
104         
105         memset(HIT, 0sizeof(HIT));
106         memset(ERR, 0sizeof(ERR));
107         memset(DIG, 0sizeof(DIG));
108         memset(KILL, 0sizeof(KILL));
109         memset(BLOCK, 0sizeof(BLOCK));
110         memset(GAMES, 0sizeof(GAMES));
111         
112         GameCount = 0;
113     }
114     
115     return 0;
116 }
117 

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理