当前位置: 首页 > 工具软件 > Battle Tanks > 使用案例 >

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

喻珂
2023-12-01

描述

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;
}
 类似资料:

相关阅读

相关文章

相关问答