10903 - Rock-Paper-Scissors Tournament
Moderator: Board moderators
-
- New poster
- Posts: 5
- Joined: Tue Oct 12, 2004 1:42 am
- Location: Poland
I received a presentation error, but I don't know why. Can anyone help?
Code: Select all
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(){
int num_of_players = 1, games_per_player, num_of_games;
while(true){
cin >> num_of_players;
if(num_of_players == 0)
break;
cin >> games_per_player;
num_of_games = games_per_player * num_of_players * (num_of_players - 1) / 2;
int win[num_of_players], game[num_of_players];
for(int i = 0; i < num_of_players; i++){
win[i] = 0;
game[i] = 0;
}
int count = 0;
int play_1 = 1, play_2;
char game_1[10], game_2[10];
while(count < num_of_games && play_1 != 0){
cin >> play_1 >> game_1 >> play_2 >> game_2;
if((game_1[0] == 'r' && game_2[0] == 'p') || (game_1[0] == 'p' && game_2[0] == 's') || (game_1[0] == 's' && game_2[0] == 'r')){
win[play_2 - 1] += 1;
game[play_2 - 1] += 1;
game[play_1 - 1] += 1;
}
else if((game_2[0] == 'r' && game_1[0] == 'p') || (game_2[0] == 'p' && game_1[0] == 's') || (game_2[0] == 's' && game_1[0] == 'r')){
win[play_1 - 1] += 1;
game[play_1 - 1] += 1;
game[play_2 - 1] += 1;
}
else{
}
cout.flush();
count++;
}
for(int j = 0; j < num_of_players; j++){
if(game[j] == 0)
cout << "-" << endl;
else
cout << setiosflags ( ios::showpoint | ios::fixed ) << setprecision(3) << win[j]/double(game[j]) << endl;
}
cout << endl;
}
return 0;
}
-
- New poster
- Posts: 11
- Joined: Tue May 22, 2007 10:09 pm
- Location: India
-
- New poster
- Posts: 38
- Joined: Tue Jul 17, 2007 3:21 pm
- Location: East West University
can't find the bug
Hi, this code is giving me WA . where is the bug ? plz help. thanks
Code: Select all
found the bug,trying to fix it. fixing in process....
Finally got AC
Eagle er moto daana meley urbo
Try this case:
Thanks
Keep posting
Sapnil
Code: Select all
Input:
2 12
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
2 8
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
Output:
0.333
0.667
0.333
0.667
Keep posting
Sapnil
help! please
hi, i tried this problem but i just get Wa, if someone have some input so i can find my mistake.
thanks.
here is my code
thanks.
here is my code
Code: Select all
got Ac
Last edited by Mata on Mon Dec 24, 2007 8:04 pm, edited 1 time in total.
Re: 10903 - Rock-Paper-Scissors Tournament
ac
Last edited by sreejond on Thu Jun 04, 2009 2:39 pm, edited 1 time in total.
Re: 10903 - Rock-Paper-Scissors Tournament
I was when I got TLE...
there's any bug?
Code: Select all
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> VI;
int main()
{
cout.setf(ios::fixed);
cout.precision(3);
int n, k, first = 1;
while (cin >> n and n)
{
if (not first) cout << endl;
first = false;
cin >> k;
int gam = k*n*(n - 1)/2;
VI win(n + 1), lose(n + 1);
while (gam--)
{
int p1, p2;
string act1, act2;
cin >> p1 >> act1 >> p2 >> act2;
if (act1 == "rock")
{
if (act2 == "scissors") { win[p1]++; lose[p2]++; }
else if (act2 == "paper") { win[p2]++; lose[p1]++; }
}
else if (act1 == "scissors")
{
if (act2 == "paper") { win[p1]++; lose[p2]++; }
else if (act2 == "rock") { win[p2]++; lose[p1]++; }
}
else
{
if (act2 == "rock") { win[p1]++; lose[p2]++; }
else if (act2 == "scissors") { win[p2]++; lose[p1]++; }
}
}
for (int i = 1; i <= n; i++)
{
double w = win[i], l = lose[i];
if (w or l) cout << w/(w + l) << endl;
else cout << '-' << endl;
}
}
}
Re: 10903 - Rock-Paper-Scissors Tournament
Can anyone explain the output for the following input? I got the output from uvatoolkit.com.
Why is there a difference in the values in the first and the second case?
Code: Select all
2 2
1 rock 2 paper
2 rock 1 paper
3 2
1 rock 2 paper
2 rock 1 paper
0
Code: Select all
0.500
0.500
0.833
0.500
-
Re: 10903 - Rock-Paper-Scissors Tournament
Hi, sreejond,sreejond wrote:hello,
i try this problem long time ago & still got WA.
Can enyone help me?
Where is my BUG?
here is my code:
I haven't seen your entire code, but just check this part
Code: Select all
if(r1==0.0 && r2==0.0)
{
printf("-\n");
break;
}