76 lines
1.1 KiB
C
76 lines
1.1 KiB
C
#include <stdio.h>
|
|
|
|
#define ROCK 1
|
|
#define PAPER 2
|
|
#define SCISSORS 3
|
|
|
|
int norm_symb(char s) {
|
|
int r = (int) s - 0x40;
|
|
|
|
if (r > 3 ) {
|
|
r -= 0x17;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
int score(int p1, int p2) {
|
|
if (p1 == p2) {
|
|
return 3;
|
|
}
|
|
|
|
switch (p2) {
|
|
case ROCK:
|
|
if (p1 == SCISSORS) return 6;
|
|
break;
|
|
case PAPER:
|
|
if (p1 == ROCK) return 6;
|
|
break;
|
|
case SCISSORS :
|
|
if (p1 == PAPER) return 6;
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int symb (int p1, int outcome) {
|
|
if (outcome == 2) return p1;
|
|
if (outcome == 1) { // need to lose
|
|
switch (p1) {
|
|
case ROCK:
|
|
return SCISSORS;
|
|
break;
|
|
case PAPER:
|
|
return ROCK;
|
|
break;
|
|
case SCISSORS:
|
|
return PAPER;
|
|
break;
|
|
}
|
|
|
|
}
|
|
switch (p1) { // need to win
|
|
case ROCK:
|
|
return PAPER;
|
|
break;
|
|
case PAPER:
|
|
return SCISSORS;
|
|
break;
|
|
case SCISSORS:
|
|
return ROCK;
|
|
break;
|
|
}
|
|
}
|
|
|
|
int main () {
|
|
char cur[20];
|
|
int p1;
|
|
int p2;
|
|
int sc = 0;
|
|
while (fgets(cur,20,stdin) != NULL) {
|
|
p1 = norm_symb(cur[0]);
|
|
p2 = symb(p1,norm_symb(cur[2]));
|
|
printf("%d %d %d\n", p1,p2, score(p1,p2));
|
|
sc += (score(p1,p2) + p2);
|
|
}
|
|
printf("%d\n", sc);
|
|
}
|