【NEEPU OJ】1036--Attack on Tanks 2 - Easy Version

本文描述了一个战车攻城的模拟场景,通过一系列指令控制战车在矩阵地图上移动,摧毁敌人并考虑墙壁的限制。文章详细介绍了游戏规则,包括战车的移动范围、墙壁的不可连续破坏以及敌人被击杀的条件。
描述

There is a battle between country A and country B. The army of country A attacked into a fortress of country B by tanks. The army of country A wants to kill all enemies in the fortress. However, there are some walls in the fortress. Equipped with tanks, the army can break walls! To simplify the problem, let’s regard the fortress as a matrix with length of n and height of m.

|------------>x

| O O O O O

| O X X C O

| O X C O O

| O O O O O

V

y

In this case, n is 5 and m is 4. X means that there is a wall in the position. C means that there is an enemy in the position. In one step, the tank can move up, down, left or right in the map. Be attention: Although we can break wall, we can’t break wall continuously. For example, if we create a coordinate system as the picture, when we had already broken a wall in (x=2,y=2) , we CANNOT break the wall (x=3,y=2) in the next move. Because of the wall fragments, if a wall has been broken, you should still regard it as a wall when you move to it again. If the tank moves onto an enemy, the enemy will be killed.

The tank is positioned at the left-top corner (x=1,y=1) first. It is guaranteed that the initial position is always empty. Given a sequence of movement, can you tell the commander of Country A’s army, are all the enemies in the fortress killed? Be attention again: the movement sequence can be invalid.

输入

There are multiple test cases. There will be a single number T(1<=T<=10) in the input indicating the test cases number. Then follows T test cases. In the beginning of each test case, there will be two integers n(2<=n<=100) and m(2<=m<=100), as described above. Then follows a n×m matrix, only containing character ‘O’, ‘X’, ‘C’, indicating empty room, a wall, and an enemy. Each character will be separated by a white space. Next line contains a number K(1<=K<=100). Then comes K strings in each line with max length 100. For each character in each string, ‘w’ means move up, ‘s’ means move down, ‘a’ means move left, and ‘d’ means move right.

输出

After doing all movements of each sequence, if all the enemies were killed, output AK in a line. If the movements are invalid, output WA in a line. If not all the enemies were killed, and the movements are valid, output AC in a line.

输入样例 1

1
5 4
O O O O O
O X X C O
O X C O O
O O O O O
5
ddssdw
ssdd
dssddwa
dadadadadadda
aass

输出样例 1

AK
AC
WA
AC
WA

来源

NEEPU 13th ACM


注意:

缓冲区的残留和scanf的正则表达式用法


代码
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
    int t, n, m, k, c, s;
    int i, j;
    int x, y, res;
    char move[1000];
    char buf[10];
    scanf("%d%*c", &t);
    if(t >= 1 && t <= 10){
        while(t--){
            c = 0;
            scanf("%d %d%*c", &n, &m);
            char matrixOXC[m][n] = {0};
            char matrixMove[m][n] = {0};
            for(i = 0; i < m; i++){
                for(j = 0; j < n; j++){
                    scanf("%s", buf);
                    matrixOXC[i][j] = buf[0];
                    if(matrixOXC[i][j] == 'C') c++;
                }
            }
            scanf("%d%*c", &k);
            char ans[k][10] = {0};
            for(i = 0; i < k; i++){
                x = 0;
                y = 0;
                s = 0;
                res = c;
                memcpy(matrixMove, matrixOXC, sizeof(matrixOXC));
                scanf("%s", move);
                for(j = 0; j < strlen(move); j++){
                    if(move[j] == 'w') y--;
                    else if(move[j] == 's') y++;
                    else if(move[j] == 'a') x--;
                    else if(move[j] == 'd') x++;
                    if(x < 0 || y < 0 || x > n - 1 || y > m - 1){
                        strcpy(ans[i], "WA");
                        s = 1;
                        break;
                    }
                    if(matrixMove[y][x] == 'C'){
                        matrixMove[y][x] = 'O';
                        res--;
                    }
                    if(matrixMove[y][x] == 'X'){
                        if(move[j] == 'w' && matrixMove[y + 1][x] == 'X'){
                            strcpy(ans[i], "WA");
                            s = 1;
                            break;
                        }
                        else if(move[j] == 's' && matrixMove[y - 1][x] == 'X'){
                            strcpy(ans[i], "WA");
                            s = 1;
                            break;
                        }
                        else if(move[j] == 'a' && matrixMove[y][x + 1] == 'X'){
                            strcpy(ans[i], "WA");
                            s = 1;
                            break;
                        }
                        else if(move[j] == 'd' && matrixMove[y][x - 1] == 'X'){
                            strcpy(ans[i], "WA");
                            s = 1;
                            break;
                        }
                    }
                }
                if(s == 0){
                    if(res == 0) strcpy(ans[i], "AK");
                    else strcpy(ans[i], "AC");
                }
            }
            for(i = 0; i < k; i++) printf("%s\n", ans[i]);
        }
    }
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值