poj 2339 Rock, Scissors, Paper
2014-04-27 10:16
176 查看
题目来源:http://poj.org/problem?id=2339
小模拟,注意字母S的大小,为此wa了几次!
小模拟,注意字母S的大小,为此wa了几次!
#include <iostream> #include <cstring> #include <cstdio> using namespace std; const int MAXN = 110; int main() { char Graph1[MAXN][MAXN], Graph2[MAXN][MAXN]; int T, row, col, days, i, j; scanf("%d", &T); while(T--) { scanf("%d %d %d", &row, &col, &days); memset(Graph1, 0, sizeof(Graph1)); memset(Graph2, 0, sizeof(Graph2)); for(i = 0; i < row; ++i) { scanf("%s", Graph1[i]); for(j = 0; j < col; ++j) Graph2[i][j] = Graph1[i][j]; Graph2[i][j] = '\0'; } while(days--)//处理这几天的变化状态 { for(i = 0; i < row; ++i) { for(j = 0; j < col; ++j) { switch(Graph1[i][j]) { case 'R'://判断R的上下左右是否为S,如果是,则用R替换掉S,以下类似 if(j-1 >= 0 && Graph1[i][j-1] == 'S') Graph2[i][j-1] = 'R'; if(j+1 < col && Graph1[i][j+1] == 'S') Graph2[i][j+1] = 'R'; if(i-1 >= 0 && Graph1[i-1][j] == 'S') Graph2[i-1][j] = 'R'; if(i+1 < row && Graph1[i+1][j] == 'S') Graph2[i+1][j] = 'R'; break; case 'S': if(j-1 >= 0 && Graph1[i][j-1] == 'P') Graph2[i][j-1] = 'S'; if(j+1 < col && Graph1[i][j+1] == 'P') Graph2[i][j+1] = 'S'; if(i-1 >= 0 && Graph1[i-1][j] == 'P') Graph2[i-1][j] = 'S'; if(i+1 < row && Graph1[i+1][j] == 'P') Graph2[i+1][j] = 'S'; break; case 'P': if(j-1 >= 0 && Graph1[i][j-1] == 'R') Graph2[i][j-1] = 'P'; if(j+1 < col && Graph1[i][j+1] == 'R') Graph2[i][j+1] = 'P'; if(i-1 >= 0 && Graph1[i-1][j] == 'R') Graph2[i-1][j] = 'P'; if(i+1 < row && Graph1[i+1][j] == 'R') Graph2[i+1][j] = 'P'; break; default: break; } } } for(i = 0; i < row; ++i) strcpy(Graph1[i], Graph2[i]); } for(i = 0; i < row; ++i) printf("%s\n", Graph1[i]); if(T) printf("\n"); } return 0; }
相关文章推荐
- POJ-2339-Rock, Scissors, Paper
- POJ 2339 Rock, Scissors, Paper(模拟)
- poj 2339 Rock, Scissors, Paper
- POJ 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- POJ 2339 Rock, Scissors, Paper 笔记
- poj 2339 Rock, Scissors, Paper 模拟
- POJ 2339 Rock, Scissors, Paper 模拟
- 模拟->YY POJ 2339 Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- POJ - 2339 Rock, Scissors, Paper
- POJ 2654 Rock-Paper-Scissors Tournament(水~)
- Coursera-An Introduction to Interactive Programming in Python (Part 1)-Mini-project— Rock-paper-scissors-lizard-Spock
- Game of Paper, Rock and scissors
- HDU 6088 Rikka with Rock-paper-scissors(莫比乌斯反演+组合数学+FFT)
- HDU 2164 Rock, Paper, or Scissors?
- Mini-project # 1 - Rock-paper-scissors-lizard-Spock
- Rock-Paper-Scissors
- HDU 6088 - Rikka with Rock-paper-scissors | 2017 Multi-University Training Contest 5