16: matrix scissors and stone
16: matrix scissors
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
5000 ms
-
Memory limit:
-
65536kB
-
Description
-
Bart's sister Lisa created a new civilization on a two-dimensional matrix. Each position on the matrix is occupied by one of three forms of life: Stone, scissors, and cloth. Each day, different forms of life are adjacent to the upper, lower, and left sides of the battle. In the battle, the stone wins scissors forever, the scissors wins the cloth forever, and the cloth wins the stone forever. After each day, the winner's territory will be occupied by the winner.
Your job is to calculate the occupancy of the matrix after n days.
-
Input
-
The first row contains three positive integers, r, c, and n, indicating the number of rows, columns, and days of the matrix, respectively. Each integer cannot exceed 100.
Next, line r contains c characters in each line, which describes the initial occupation of the matrix. The characters at each position can only be one of R, S, and P, which respectively represent stone, scissors, and cloth. There is no space between adjacent characters.
-
Output
-
Output The Matrix size after n days. The characters at each position can only be one of R, S, and P, and there is no space between adjacent characters.
-
Sample Input
-
3 3 1RRRRSRRRR
-
Sample output
-
RRRRRRRRR
-
Source
-
Waterloo local 2003.01.25
-
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 6 char a[110][110],b[110][110]; 7 int n,m,t; 8 9 int main()10 {11 cin >> n >> m >> t;12 for(int i=1;i<=n;i++)13 for(int j=1;j<=m;j++)14 {15 cin>>a[i][j];16 b[i][j]=a[i][j];17 }18 for(int k=1;k<=t;k++)19 {20 for(int i=1;i<=n;i++)21 for(int j=1;j<=m;j++)22 {23 if(a[i][j]=='R')24 {25 if(a[i-1][j]=='S')b[i-1][j]='R';26 if(a[i+1][j]=='S')b[i+1][j]='R';27 if(a[i][j-1]=='S')b[i][j-1]='R';28 if(a[i][j+1]=='S')b[i][j+1]='R';29 }30 if(a[i][j]=='S')31 {32 if(a[i-1][j]=='P')b[i-1][j]='S';33 if(a[i+1][j]=='P')b[i+1][j]='S';34 if(a[i][j-1]=='P')b[i][j-1]='S';35 if(a[i][j+1]=='P')b[i][j+1]='S';36 }37 if(a[i][j]=='P')38 {39 if(a[i-1][j]=='R')b[i-1][j]='P';40 if(a[i+1][j]=='R')b[i+1][j]='P';41 if(a[i][j-1]=='R')b[i][j-1]='P';42 if(a[i][j+1]=='R')b[i][j+1]='P';43 }44 }45 for(int i=1;i<=n;i++)46 for(int j=1;j<=m;j++)47 a[i][j]=b[i][j];48 }49 for(int i=1;i<=n;i++)50 {51 for(int j=1;j<=m;j++)52 cout << b[i][j];53 cout << "\n";54 }55 return 0;56 }