首页 > 代码库 > RQNOJ PID51 / 乒乓球 ☆

RQNOJ PID51 / 乒乓球 ☆

因为是多行输入,所以用了getchar()进行输入,题目没有说明数据范围,所以开始的时候因为数组开的不够大,WA90了一次,我之前开了10000的长度,之后开100000的长度跑过了

一个基本的模拟,没什么套路

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
  int c;
  int W[100000],L[100000];
  int W2[100000],L2[100000];
  memset(W2,0,sizeof(W2));
  memset(L2,0,sizeof(L2));
  memset(W,0,sizeof(W));
  memset(L,0,sizeof(L));
  int count_r=0;
  int count_R=0;
  //int dou_w=0,dou_l=0,ele_w=0,ele_l=0;
  while((c=getchar())!=EOF)
  {
     if(c==W)
     {
         W[count_r]++;
         W2[count_R]++;
     }
     if(c==L)
     {
         L[count_r]++;
         L2[count_R]++;
     }
     if(W[count_r]>=11&&W[count_r]-L[count_r]>=2||L[count_r]>=11&&L[count_r]-W[count_r]>=2)
     {
         count_r++;
     }
     if(W2[count_R]>=21&&W2[count_R]-L2[count_R]>=2||L2[count_R]>=21&&L2[count_R]-W2[count_R]>=2)
     {
         count_R++;
     }
     if(c==E)
     {

        for(int i=0;i<=count_r;i++)
        {
            cout<<W[i]<<":"<<L[i]<<endl;
        }
        cout<<endl;
        for(int i=0;i<=count_R;i++)
        {
            cout<<W2[i]<<":"<<L2[i]<<endl;
        }
        break;
     }

  }
    return 0;
}

 

RQNOJ PID51 / 乒乓球 ☆