Algorithm


Problem link- https://www.spoj.com/problems/CERC07R/

CERC07R - Reaux! Sham! Beaux!

no tags 

 

Roshambo - this simple game is known all around the world. In German, it is called "Schnick, Schnack, Schnuck", in Japanese "Janken", in Spanish "Cachipún",in Polish "Papier, kamień, nożyce". The Czechs call it "Kámen, nůžky, papír".

Whatever is the name of the game, its principles remain the same. Two players simultaneously form their hand into one of three possible shapes (symbols): Rock (closed fist), Paper (open hand), or Scissors (two fingers extended). If both of them show the same symbol, it is a tie and no points are given. Otherwise, one of the symbols wins: Rock blunts Scissors, Scissors cut Paper, and Paper covers Rock.

Czech Technical University students also know the game very well and use it to resolve small disputes. Imagine, for example, two students living together in one room. Yesterday evening, there was a small celebration, and in the morning, no one wants to go to the lectures. They agreed that one person would be enough to take notices for both, but who will be the poor one. Roshambo is a very effective way to decide.

Did you know there are even the World Series of Roshambo. Our organizing team would like to host the World Championships in 2009. Your task is to help us in developing a Roshambo scoring system and write a program that evaluates one game between two players.

Since the participants will come from different countries, the system must accept input in various languages. The following table shows names of three Roshambo symbols. Note that in some languages, there may be two different words for the same symbol.

 

Language Code Rock Scissors Paper
Czech
English
French
German
Hungarian
Italian
Japanese
Polish
Spanish
cs
en
fr
de
hu
it
jp
pl
es
Kamen
Rock
Pierre
Stein
Ko | Koe
Sasso | Roccia
Guu
Kamien
Piedra
Nuzky
Scissors
Ciseaux
Schere
Ollo | Olloo
Forbice
Choki
Nozyce
Tijera
Papir
Paper
Feuille
Papier
Papir
Carta | Rete
Paa
Papier
Papel

Input

The input contains several games. Each game starts with two lines describing players. Each of these two lines contains two lowercase letters specifying the language used by the player (see the language code in the table above), one space, and a player name. The name will consist from at most twenty upper- or lower-case letters.

After the players description, there are at most 100 lines containing individual rounds. Each round is described by two words separated with one space. The words name the symbol shown by the first and second player, respectively. All symbols are named in the mother tongue of the concerned player. All allowed words are shown in the table above, the first letter will be always in uppercase, all other letters in lowercase.

The last round is followed by a line containing one single dash character ("-") and then the next game begins. The only exception is the last game in the input, which is terminated by a dot (".") instead of the dash.

Output

For each game, print five lines of output. The first line should contain the string "Game #G:", where G is the number of the game, starting with one.

The second line will contain the first player name followed by a colon (":"), one space and the number of rounds won by that player. The number should be followed by one space and the word "points". Use the singular form "point" if (and only if) the number of points of the player equals one.

The third line has the same format and shows the second player's name and points.

The fourth line displays the outcome of the game. It must contain the word "WINNER" followed by a colon, space and the name of the player who gained more points. If both players have the same number of points, the fourth line will contain words "TIED GAME" instead.

The fifth line is left empty to visually separate individual games.

Example

Input
cs Pepik
en Johnny
Nuzky Scissors
Papir Rock
Papir Scissors
-
de Gertruda
cs Lenka
Stein Papir
Schere Kamen
.

Output
Game #1:
Pepik: 1 point
Johnny: 1 point
TIED GAME

Game #2:
Gertruda: 0 points
Lenka: 2 points
WINNER: Lenka

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdlib>
#include <map>
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
      map <string, int> m;
      m["Kamen"] = m["Rock"] = m["Pierre"] = m["Stein"] = m["Ko"] = m["Koe"] = m["Sasso"] = m["Roccia"] = m["Guu"] = m["Kamien"] = m["Piedra"] = 1;
      m["Nuzky"] = m["Scissors"] = m["Ciseaux"] = m["Schere"] = m["Ollo"] = m["Olloo"] = m["Forbice"] = m["Choki"] = m["Nozyce"] = m["Tijera"] = 2;
      m["Papir"] = m["Paper"] = m["Feuille"] = m["Papier"] = m["Papir"] = m["Carta"] = m["Rete"] = m["Paa"] = m["Papier"] = m["Papel"] = 3;
      
      string name1,name2,l1,l2,x1,x2;
      int p1,p2,t1,t2,z=1;
      bool bb=false;
      while(1)
      {
			cin>>l1;
			if(l1 == "."||bb)break;
			cin>>name1>>l2>>name2;
			p1=p2=0;
			while(1)
			{
				cin>>x1;
				if(x1==".")
				{
					bb=true;
					break;
				}
				if(x1=="-")break;
				cin>>x2;
				t1=m[x1];
				t2=m[x2];
				if(t1==t2)continue;
				if(t1==1&&t2==2)p1++;
				if(t1==1&&t2==3)p2++;
				if(t1==2&&t2==1)p2++;
				if(t1==2&&t2==3)p1++;
				if(t1==3&&t2==1)p1++;
				if(t1==3&&t2==2)p2++;
			}
			cout << "Game #" << z++ << ":\n" << name1 << ": " << p1;
			if(p1 == 1) printf(" point\n");
            else printf(" points\n");
            cout << name2 << ": " << p2;
            if(p2 == 1) printf(" point\n");
            else printf(" points\n");
            if(p1 == p2) printf("TIED GAME\n\n");
            else
            {
                printf("WINNER: ");
                cout << (p1 > p2 ? name1 : name2) << endl << endl;
            }
	  }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
cs Pepik
en Johnny
Nuzky Scissors
Papir Rock
Papir Scissors
-
de Gertruda
cs Lenka
Stein Papir
Schere Kamen
.

Output

x
+
cmd
Game #1:
Pepik: 1 point
Johnny: 1 point
TIED GAME
Game #2:
Gertruda: 0 points
Lenka: 2 points
WINNER: Lenka
Advertisements

Demonstration


SPOJ Solution-Reaux! Sham! Beaux!-Solution in C, C++, Java, Python

Previous
SPOJ Solution - Test Life, the Universe, and Everything - Solution in C, C++, Java, Python