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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值