Page 2 of 2

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Sat Sep 05, 2009 5:58 am
by craigofoasis
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;
}

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Sat Sep 05, 2009 6:06 am
by sp2hari
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: }

RTE!!

Posted: Sat Jan 02, 2010 11:29 pm
by shinningangel

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 ><

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Sun Oct 24, 2010 2:45 pm
by Shafaet_du
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 :).

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Sun Oct 31, 2010 5:20 pm
by falcon1082
i did'n get WA
but i keep getting RE
what's matter with my code?

please help me

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]));
		}
	}
}


10903 [SE] Rock-Paper-Scissors Tournament

Posted: Sun Jul 07, 2013 11:24 am
by gkevinyen5418
i dont know why i keep getting SE
even i submit a AC code
which i search on the Net

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

Posted: Mon Jul 08, 2013 11:05 pm
by brianfry713
Try a different problem.

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Sat Nov 08, 2014 2:25 pm
by uDebug
Replying to follow the thread.

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Tue Nov 11, 2014 10:50 pm
by gautamzero
i'm getting runtime error... :(
why??

Code: Select all

removed after AC

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Fri Nov 14, 2014 6:34 pm
by MPC1984
Hi everybody!
I'm getting WA in this problem and I don't know why. Someone could help me?

Code: Select all

AC
Thanks in advance! :wink:

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Tue Nov 18, 2014 2:48 am
by brianfry713
gautamzero
k*n*(n-1)/2 games in total

MPC1984, that is AC code.

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Sun Nov 23, 2014 10:46 am
by gautamzero
thanks brianfry713.. :D

Re: 10903 - Rock-Paper-Scissors Tournament

Posted: Mon Nov 24, 2014 1:21 pm
by MPC1984
Thank you brianfry713, but I don't know why I'm getting WA if it's an AC code. :roll: