When there is only one round, the winner of that single round is the overall winner of the game.
Algorithm:
A, Alice wins the gameB, Bob wins the gameTime Complexity:
Space Complexity:
For the general case, we need to count how many rounds each player won and determine who has more wins.
Key Observation:
Since is always odd, there cannot be a tie. Therefore, one player will always have strictly more wins than the other.
Algorithm:
A characters to get B characters to get (alternatively, )Time Complexity: — for counting characters in the string
Space Complexity: — for storing the input string (or if we count while reading)
#include <iostream>
#include <string>
using namespace std;
int main() {
int N;
string rounds;
cin >> N >> rounds;
int alice_wins = 0;
int bob_wins = 0;
for (char ch : rounds) {
if (ch == 'A') {
alice_wins++;
} else {
bob_wins++;
}
}
if (alice_wins > bob_wins) {
cout << "Alice" << endl;
} else {
cout << "Bob" << endl;
}
return 0;
}