Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/
#include <stdio.h>
int main()
{
int p, j1, j2, r, a, win, sum;
scanf("%d %d %d %d %d", &p, &j1, &j2, &r, &a);
sum = j1 + j2;
if((sum%2==0 && p==1) || (sum%2==1 && p==0)) win = 1;
else win = 2;
if((r==1 && a==0) || (r==0 && a==1)) win = 1;
else if(r==1 && a==1) win=2;
printf("Jogador %d ganha!\n", win);
return 0;
}
What's wrong in this code?
ReplyDelete(Wrong answer (10%))
#include
int main(){
int p, j1, j2, r, a, x;
scanf("%d %d %d %d %d", &p, &j1, &j2, &r, &a);
x= (j1+j2) %2;
if (x==0) {
if ((p==1) || (p==0 && r==1 && a==0))
printf("Jogador 1 ganha!\n");
else printf("Jogador 2 ganha!\n");
}
else if (x!=0) {
if ((p==0) || (p==1 && r==1 && a==0))
printf("Jogador 1 ganha!\n");
else printf("Jogador 2 ganha!\n");
}
return 0;
}