Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams’ actions in the final battle. Figure out who became the champion.
Input
The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team.
Output
Output “TEAM 1 WINS” if the first team won, “TEAM 2 WINS” if the second team won, and “TIE” if there was a tie.
Examples
input
[]()[]8<
8<[]()8<
output
TEAM 2 WINS
input
8<8<()
[]8<[]
output
TIE
Solution:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;
char a[444], b[444];
int main() {
scanf("%s", a);
scanf("%s", b);
int n = strlen(a);
int res = 0;
for (int i = 0; i < n; i += 2) {
int x = (a[i] == '8' ? 0 : (a[i] == '(' ? 1 : 2));
int y = (b[i] == '8' ? 0 : (b[i] == '(' ? 1 : 2));
if (x == y) {
continue;
}
if ((x + 1) % 3 == y) {
res++;
} else {
res--;
}
}
puts(res == 0 ? "TIE" : (res < 0 ? "TEAM 1 WINS" : "TEAM 2 WINS"));
return 0;
}
Related posts:
Circle-Circle Intersection
Spaceship Solitaire
Cycles
Minimum spanning tree - Kruskal with Disjoint Set Union
Two-gram
Deleting from a data structure in $O(T(n)\log n)$
Obsessive String
Restoring Three Numbers
Infinite Path
Refactoring
Hongcow Builds A Nation
Restoring Map
The Holmes Children
Primitive Root
Subarray Cuts
Exercising Walk
Pudding Monsters
Stairs and Elevators
New Year Permutation
Sharti
Wilbur and Strings
Bash Plays with Functions
New Year and the Permutation Concatenation
Maximum flow - Push-relabel method improved
Tổng hợp các bài toán duyệt với gợi ý lời giải
Marvolo Gaunt's Ring
Bacterial Melee
PolandBall and White-Red graph
Three Integers Again
Zoning Restrictions
Looksery Party
Aho-Corasick algorithm