zoukankan      html  css  js  c++  java
  • poj2339

    简单题

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define maxn 105

    int n, m, d;
    char map[2][maxn][maxn];
    int dir[4][2] =
    {
    {
    1, 0 },
    {
    0, 1 },
    {
    -1, 0 },
    {
    0, -1 } };

    void input()
    {
    scanf(
    "%d%d%d", &n, &m, &d);
    getchar();
    for (int i = 1; i <= n; i++)
    {
    for (int j = 1; j <= m; j++)
    map[
    0][i][j] = getchar();
    getchar();
    }
    }

    char getop(char a)
    {
    if (a == 'R')
    return 'P';
    if (a == 'P')
    return 'S';
    return 'R';
    }

    void work()
    {
    for (int i = 0; i < d; i++)
    {
    for (int j = 1; j <= n; j++)
    for (int k = 1; k <= m; k++)
    {
    char ch = getop(map[i & 1][j][k]);
    map[(i
    + 1) & 1][j][k] = map[i & 1][j][k];
    for (int l = 0; l < 4; l++)
    if (map[i & 1][j + dir[l][0]][k + dir[l][1]] == ch)
    {
    map[(i
    + 1) & 1][j][k] = ch;
    break;
    }
    }
    }
    }

    void print()
    {
    int x = d & 1;
    for (int i = 1; i <= n; i++)
    {
    for (int j = 1; j <= m; j++)
    putchar(map[x][i][j]);
    putchar(
    '\n');
    }
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    int t;
    scanf(
    "%d", &t);
    while (t--)
    {
    input();
    work();
    print();
    if (t > 0)
    putchar(
    '\n');
    }
    return 0;
    }
  • 相关阅读:
    学习进度条08
    学习进度条07
    子数组和最大值(二维)
    学习进度条06
    构建之法阅读笔记04
    四则运算网页版
    泛型代码中的默认关键字
    js 日期大小比较
    c#Reverse字符串
    c#获取数组中指定元素的索引
  • 原文地址:https://www.cnblogs.com/rainydays/p/2122101.html
Copyright © 2011-2022 走看看