BOJ 1561 Winner

Winner
Accept:8     Submit:15
Time Limit:1000MS     Memory Limit:65536KB

Winner

 

Description

 

Alice and Bob likes playing games. In each round, the one who wins will get one point. When one of them makes his/her points reach 11 firstly, we say he/she has won a set of game, and they will start the next set. However, the rules are a little strange: the loser would start the new set of game with the points that he/she has got in the last set. The one who wins 4 sets firstly becomes the final winner. For instance, we have their playing results in each round:

A A A B B A A A B B A A A B A A

where 'A' indicates Alice wins, and 'B' stands for Bob's winning. We can easily find that Alice has got 11 points, and Bob only wins 5. Therefore, Alice is the winner of this set, but the next set of game will start with 0 : 5, where Bob leads the game by 5 points.

Given all their results in each round, you're required to find who wins the game finally. Note that the game may ends before we goes along all the given results.

Input Format

 

An integer T(T50) 
will exist in the first line of input, indicating the number of test cases.

Each test case is a string which contains only letter 'A' or 'B'. The length of each string will not exceed 10000.

The test data guarantees that the winner always exists.

Output Format

 

Output 'Alice' if Alice wins, otherwise output 'Bob'.

Sample Input

 
1
AAAAAAAAAAABBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBB
 

Sample Output

 
Alice

第一天大一排位赛的第一题,水题一道直接贴代码

 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int t;
 8     long alice_win,bob_win,alice_point,bob_point;
 9     char result[10050];
10 
11     cin>>t;
12 
13     while(t--)
14     {
15         cin>>result;
16         alice_win=bob_win=alice_point=bob_point=0;
17         for(int i=0;i<=10000;i++)
18         {
19             if(result[i]=='A')
20                 alice_point++;
21             else if(result[i]=='B')
22                 bob_point++;
23             if(alice_point==11)
24             {
25                 alice_win++;
26                 alice_point=0;
27             }
28             else if(bob_point==11)
29             {
30                 bob_win++;
31                 bob_point=0;
32             }
33             if(alice_win==4)
34             {
35                 cout<<"Alice"<<endl;
36                 break;
37             }
38             else if(bob_win==4)
39             {
40                 cout<<"Bob"<<endl;
41                 break;
42             }
43         }
44     }
45 
46     return 0;
47 }
[C++]
 
原文地址:https://www.cnblogs.com/lzj-0218/p/3181336.html