## 10903 - Rock-Paper-Scissors Tournament

Moderator: Board moderators

craigofoasis
New poster
Posts: 1
Joined: Sat Sep 05, 2009 2:11 am

### Re: 10903 - Rock-Paper-Scissors Tournament

I am having a terrible time: I keep getting wrong answer, though my numbers are correct
How (Where) do they expect the carriage returns? I keep trying it different ways: optimised for manually entering from the command line, and also piping data (e.g. ./RPS <in.txt >out.txt or Windows variant)

I have tried this several different ways, with it doing an extra line between cases and not. (I always make sure there is no extra line at the end.)

Code: Select all

``````#include <iostream>
using namespace std;

int main (int argc, char * const argv[]) {
// Topher Craig attempt at UVa problem Rock, Paper, Scissors
// Beginning Mon, Aug 24 2009

int n, k;

while (true){
cin >> n;
if(n == 0) break;

cin >> k;

int* won= new int[n];
int* count= new int[n];
for (int i=0; i<n; i++){
won[i]=0;
count[i]=0;
}
char play1[11], play2[11];
for (int i=0, hold1, hold2; i<k*n*(n-1)/2; i++){

cin >> hold1 >> play1 >> hold2 >> play2;

if (play1[0]!=play2[0]){
count[hold1-1]++;
count[hold2-1]++;
if(play1[0]=='r'){
if(play2[0]=='s')won[hold1-1]++;
else won[hold2-1]++;
}
else if (play1[0]=='p'){
if(play2[0]=='r')won[hold1-1]++;
else won[hold2-1]++;
}
else{
if(play2[0]=='p')won[hold1-1]++;
else won[hold2-1]++;
}
}
}

cout << fixed << showpoint;
for (int i=0; i<n; i++){
if(count[i] > 0){
cout.precision(3);
cout << static_cast<float>(won[i])/count[i]<<endl;
}
else cout <<"-"<<endl;
}

delete []won;
delete []count;
}
return 0;
}
``````

sp2hari
New poster
Posts: 3
Joined: Sun Nov 09, 2008 10:56 pm

### Re: 10903 - Rock-Paper-Scissors Tournament

The following code should help you. It doesn't contain the main logic which calculates the winner... Don't try to copy or compile the code.. There is no way it'll work.

Code: Select all

``````26: int main() {
27:         int players, games;
30:         bool first = true;
31:         while (scanf("%d", &players) != -1) {
32:                 if (first == false) printf("\n");
33:                 if (players == 0) break;
34:                 scanf("%d", &games);
35:                 if (first == false) printf("\n");
36:                 first = false;
37:                 vector <int> scores (players, 0), total(players, 0);
38:                 int gamecount = games * players * (players-1);
39:                 gamecount /= 2;
40:                 REP(i, gamecount) {
42:                         scanf("%d%s%d%s", &p1, &t_m1, &p2, &t_m2);
54:                 }
56:                 REP(i, players) {
57:                         double cur;
58:                         if (total[i] > 0) {
60:                                 printf("%0.3lf", cur);
61:                         }
62:                         else {
63:                                 printf("-");
64:                         }
65:                         if (i != players-1) printf("\n");
66:                 }
67:         }
68:         return 0;
69: }
``````

shinningangel
New poster
Posts: 2
Joined: Sat Nov 28, 2009 9:12 am

### RTE!!

Code: Select all

``````#include <stdio.h>
int main(){
int i,j,x,n,k;
int num_game;
while(scanf("%d",&n)==1){
if(n==0) break;
scanf("%d",&k);
double win[n],lose[n];
int player[n];
int suit_case[n];
num_game=(k*n*(n-1))/2;

for(x=0;x<n;x++){
win[x]=0;
lose[x]=0;
}

for(i=0;i<num_game;i++){
char A[9]={0};
for(j=0;j<n;j++){
scanf("%d %s",&player[j],&A);   /*this loop to save each player input*/
if(A[0]=='r') suit_case[j]=1;    /*rock*/
if(A[0]=='p') suit_case[j]=2;    /*paper*/
if(A[0]=='s') suit_case[j]=3;    /*scissor*/

}

for(x=0;x<n;x++){
if(suit_case[x]==1){                /*if rock*/
for(j=0;j<n;j++){
if(suit_case[j]==2) win[player[j]-1]++;
if(suit_case[j]==3) lose[player[j]-1]++;
}
}

if(suit_case[x]==2){                /*if paper*/
for(j=0;j<n;j++){
if(suit_case[j]==3) win[player[j]-1]++;
if(suit_case[j]==1) lose[player[j]-1]++;
}
}

if(suit_case[x]==3){                /*if scissors*/
for(j=0;j<n;j++){
if(suit_case[j]==1) win[player[j]-1]++;
if(suit_case[j]==2) lose[player[j]-1]++;
}
}
}
}

for(x=0;x<n;x++){
if((win[x]+lose[x])==0) printf("-\n");
else printf("%.3lf\n",(win[x]/(win[x]+lose[x])));
}printf("\n");

}
return 0;
}
``````
-->>what wrong with my program!? it got running time error.. I already tried sample input, and it works fine, even in cmd ><

Shafaet_du
Experienced poster
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Contact:

### Re: 10903 - Rock-Paper-Scissors Tournament

sp2hari's input on last page which he tested on toolkit is not valid. Notice that k*n*(n-1)/2 game in total. If win+loose=0 print "-",otherwise you may get RTE. eps is not needed.

good luck .

falcon1082
New poster
Posts: 1
Joined: Sun Oct 31, 2010 5:12 pm

### Re: 10903 - Rock-Paper-Scissors Tournament

i did'n get WA
but i keep getting RE
what's matter with my code?

Code: Select all

``````#include<iostream>
#define Max 101
#define sMax 11
using namespace std;

struct game
{
int p1, p2;
char h1[sMax], h2[sMax];
} g[Max];

int n, k, win[Max], tie[Max];

int h[256];
int  w_s[3][3] = {{0, 1, -1}, {-1, 0, 1}, {1, -1, 0}};
bool flag;

int main()
{
int times, i, t, a, b;

h['p'] = 0;
h['r'] = 1;
h['s'] = 2;

while(scanf("%d", &n) == 1 && n!=0)
{
memset(g, 0, sizeof(g));
memset(win, 0, sizeof(win));
memset(tie, 0, sizeof(tie));

scanf("%d", &k);

times = n * (n - 1) * k / 2;

for(i = 0; i < times; i++)
scanf("%d %s %d %s", &g[i].p1, g[i].h1, &g[i].p2, g[i].h2);

for(i = 0; i < times; i++)
{
t = w_s[ h[g[i].h1[0] ]][ h[g[i].h2[0]] ];

a = g[i].p1, b = g[i].p2;

if(t > 0)
win[a]++;
else if(t < 0)
win[b]++;
else
{
tie[a]--;
tie[b]--;
}
}

if(flag == 0)
flag = 1;
else
printf("\n");

for(i = 1; i <= n; i++)
{
if(times * 2 / n + tie[i] <= 0)
{
printf("-\n");
continue;
}
printf("%.3lf\n", (double)win[i] / ((times * 2 / n) + tie[i]));
}
}
}

``````

gkevinyen5418
New poster
Posts: 3
Joined: Wed Jul 03, 2013 2:35 pm

### 10903 [SE] Rock-Paper-Scissors Tournament

i dont know why i keep getting SE
even i submit a AC code
which i search on the Net

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10903 [SE] Rock-Paper-Scissors Tournament

Try a different problem.
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 10903 - Rock-Paper-Scissors Tournament

Check input and AC output for over 7,500 problems on uDebug!

gautamzero
New poster
Posts: 32
Joined: Fri Oct 10, 2014 1:10 pm

### Re: 10903 - Rock-Paper-Scissors Tournament

i'm getting runtime error...
why??

Code: Select all

``````removed after AC
``````
Last edited by gautamzero on Sun Nov 23, 2014 10:46 am, edited 1 time in total.
None but a fool is always right..
so don't be upset when u r wrong..

MPC1984
New poster
Posts: 40
Joined: Mon Jul 01, 2013 9:24 pm

### Re: 10903 - Rock-Paper-Scissors Tournament

Hi everybody!
I'm getting WA in this problem and I don't know why. Someone could help me?

Code: Select all

``````AC
``````
Last edited by MPC1984 on Mon Nov 24, 2014 1:19 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10903 - Rock-Paper-Scissors Tournament

gautamzero
k*n*(n-1)/2 games in total

MPC1984, that is AC code.
Check input and AC output for thousands of problems on uDebug!

gautamzero
New poster
Posts: 32
Joined: Fri Oct 10, 2014 1:10 pm

### Re: 10903 - Rock-Paper-Scissors Tournament

thanks brianfry713..
None but a fool is always right..
so don't be upset when u r wrong..

MPC1984
New poster
Posts: 40
Joined: Mon Jul 01, 2013 9:24 pm