1363: [NOIP2003] Table Tennis T1

topic description

Huahua conducts the analysis in the following way. First, the winners and losers of each ball in the game are listed in a table, and then the results of the two sides' matches under the 11-point system and 21-point system are calculated respectively (as of the end of the record). For example, there is such a record now (where W means that Huahua gets one point, and L means that Huahua’s opponent gets one point): WWWWWWWWWWWWWWWWWWWWWLW Under the 11-point system, the result of the game at this time is that Huahua won the first game 11-0 , won the second game 11-0, and the third game is in progress, the current score is 1-1. Under the 21-point system, the result of the game at this time is that Huahua won the first game 21-0, and the second game is in progress, with a score of 2-1. If a game has just started, the score is 0-0 at this time. Your program is to output the correct result for a series of game information input (WL form).

enter

Each input file contains several lines of strings (up to 20 letters per line), consisting of uppercase W, L, and E, with perhaps several spaces in between. Where E means the end of the game information, the program should ignore all content after E, there may be interfering words after E.

output

The output consists of two parts, each part has several lines, and each line corresponds to the score of a game (according to the order of game information input). The first part is the result under the 11-point system, the second part is the result under the 21-point system, and the two parts are separated by a blank line.

sample input

WWWWWWWWWWWWWWWWWWWW

WWLWE

sample output

11:0

11:0

1:1

21:0

2:1

hint

Very simple, be careful with input and output formats! ^_^

The number of answer sessions will not exceed 5000.

Not much to say, the code

#include<iostream>
#include<cstring>
using namespace std;
int win[62503];
int w,l;
int main()
    { 
     char s;
     for(int i=1;cin>>s&&s!='E';i++)
     { 
      if(s=='W') win[i]=1;
      else win[i]=2;
     }
     for(int i=1;1;i++)
     { 
      if(win[i]==1) w++;
      if(win[i]==2) l++;
      if(win[i]==0)
      { 
       cout<<w<<":"<<l<<endl<<endl;
       break;
      }
      if(w-l>=2||l-w>=2)
      { 
       if(w>=11||l>=11)
       { 
        cout<<w<<":"<<l<<endl;
        w=0;
        l=0;
       }
      }
     }
     w=0;
     l=0;
     for(int i=1;1;i++)
        { 
          if(win[i]==1) w++;
          if(win[i]==2) l++;
          if(win[i]==0)
          { 
       cout<<w<<":"<<l<<endl<<endl;
          break;
          }
          if(w-l>=2||l-w>=2)
          { 
       if(w>=21||l>=21)
          { 
        cout<<w<<":"<<l<<endl;
        w=0;
         l=0;
        }
    }
        }
    return 0;
}

Remember to like + follow

Guess you like

Origin blog.csdn.net/qiuweichen1215/article/details/129230655