Code: Select all
cutted..
Dominik
Moderator: Board moderators
Code: Select all
cutted..
can anyone tell what's wrong??INPUT :
10
0 0 3
1 1 3
R
1 10 4
SRPSRPPRSR
10 1 4
R
S
P
P
S
R
R
S
P
P
3 3 1
RRR
RSR
RRR
3 3 1000
RRR
RSR
RRR
3 4 3
RSPR
SPRS
PRSP
3 4 2
RSPR
SPRS
PRSP
3 4 3
PRSP
RSPR
SPRS
5 5 5
RRRSP
RSRSP
RRRRP
SRRRP
RPPRP
OUTPUT :
[a blank line]
R
RPPPPPPPPP
R
R
R
R
R
R
R
R
R
R
RRR
RRR
RRR
RRR
RRR
RRR
RRRR
RRRS
RRSP
RRRS
RRSP
RSPR
PPPP
PPPR
PPRS
PPPSP
PPSRS
PSRPP
PPSRP
PPPSR
Rock. What other possibility did you have in mind?yan4546 wrote:In the following case ,who will take up the grid where the 'S' is in, after 1 day's war? And Why???
_R_
RSP
_P_
Code: Select all
cutted
Code: Select all
#include<stdio.h>
#include<malloc.h>
#include<string.h>
int A_beats_B(char a, char b)
{
return (a=='R'&&b=='S')||(a=='S'&&b=='P')||(a=='P'&&b=='R');
}
main()
{
int cases;
int i,j,r,c,n,day,num,copy;
char **grid,**copy_grid;
scanf("%d",&cases);
for (num=0;num<cases;num++)
{
scanf("%d %d %d",&r,&c,&n);
getchar();
grid=(char **)malloc(r*sizeof(char *));
copy_grid=(char **)malloc(r*sizeof(char *));
for(i=0;i<r;i++)
{
grid[i]=(char *)malloc(c*sizeof(char));
copy_grid[i]=(char *)malloc(c*sizeof(char));
}
for (i=0;i<r;i++)
{
gets(grid[i]);
strcpy(copy_grid[i],grid[i]);
}
for (day=0;day<n;day++)
{
for (i=0;i<r;i++)
{
for (j=0;j<c;j++)
{
if (j>0)
{
if (A_beats_B(copy_grid[i][j],copy_grid[i][j-1]))
grid[i][j-1]=copy_grid[i][j];
else
grid[i][j]=copy_grid[i][j-1];
}
if (i>0)
{
if (A_beats_B(copy_grid[i][j],copy_grid[i-1][j]))
grid[i-1][j]=copy_grid[i][j];
else
grid[i][j]=copy_grid[i-1][j];
}
if (j<c-1)
{
if (A_beats_B(copy_grid[i][j],copy_grid[i][j+1]))
grid[i][j+1]=copy_grid[i][j];
else
grid[i][j]=copy_grid[i][j+1];
}
if (i<r-1)
{
if (A_beats_B(copy_grid[i][j],copy_grid[i+1][j]))
grid[i+1][j]=copy_grid[i][j];
else
grid[i][j]=copy_grid[i+1][j];
}
}
}
for(copy=0;copy<r;copy++)
strcpy(copy_grid[copy],grid[copy]);
}
for(i=0;i<r;i++)
puts(grid[i]);
if(num!=cases-1)
printf("\n");
}
}