Re: 10903 - Rock-Paper-Scissors Tournament
Posted: Sat Sep 05, 2009 5:58 am
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.)
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;
}