Problem Statement: 1999A — A+B Again?
Since $$$n$$$ is a two-digit number, you can access each digit by simple arithmetic operations.
To find the sum of digits of a two-digit number $$$n$$$, divide $$$n$$$ by 10 to get the first digit and take $$$n$$$ modulo 10 to get the second digit. Adding these gives the desired result.
Time Complexity: $$$O(1)$$$ per test case Space Complexity: $$$O(1)$$$
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n / 10) + (n % 10) << endl;
return 0;
}
Problem Statement: B — Card Game
For each pair of cards, consider all possible matchups and count how many games Suneet can win by winning more rounds.
Each player has two cards, and the game consists of two rounds. For each matchup of cards, there are four possible ways for the players to reveal their cards. We simulate each of these cases and count how many result in Suneet winning more rounds than Slavic.
Time Complexity: $$$O(1)$$$ per test case
Space Complexity: $$$O(1)$$$
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a1, a2, b1, b2;
cin >> a1 >> a2 >> b1 >> b2;
int count = 0;
int a[2] = {a1, a2}, b[2] = {b1, b2};
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
int suneet = 0, slavic = 0;
if (a[i] > b[j]) suneet++;
else if (a[i] < b[j]) slavic++;
if (a[1 - i] > b[1 - j]) suneet++;
else if (a[1 - i] < b[1 - j]) slavic++;
if (suneet > slavic) count++;
}
}
cout << count << endl;
}
return 0;
}