poj 2339 Rock, Scissors, Paper
来源:互联网 发布:seo顾问服务 博客 编辑:程序博客网 时间:2024/05/16 11:06
题目来源:http://poj.org/problem?id=2339
小模拟,注意字母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;}
0 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 模拟
- 模拟->YY POJ 2339 Rock, Scissors, Paper
- POJ 2339 Rock, Scissors, Paper(模拟)
- POJ 2339 Rock, Scissors, Paper 模拟
- POJ 2339 Rock, Scissors, Paper 笔记
- poj 3917 Rock, Paper, Scissors
- poj 2654 Rock-Paper-Scissors Tournament
- POJ-2654-Rock-Paper-Scissors Tournament
- POJ 3917 Rock, Paper, Scissors G++
- Rock-Paper-Scissors
- 【poj2339】Rock, Scissors, Paper
- 异常处理 org.springframework.beans.factory.BeanCreationException
- asp.net 连接sql server 2005 数据库的设置
- 一步一步跟我做个出类拔萃经的住考验的系统:
- 命令行启动android emulator及用adb加载应用程序 .
- 消息通信库ZeroMQ 4.0.4安装指南
- poj 2339 Rock, Scissors, Paper
- matlab标定和三维重建的几个问题(已解决)
- redis 事件
- dede:channelartlist 判断
- Maven3创建web项目
- Linux Shell常用技巧(目录)
- 客户端调用webService
- Servlet Filter Servlet Listener
- mongodb 数据库 第一章 安装