【NEEPU OJ】1012--Where is the gold?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34072526/article/details/88220113

描述

In some popular strategy games like World of Warcraft or Age of Empires, a player has to look for gold mines in a map to build his/her nation. Gold mine is important for success in the game and any player who can find gold mines quickly can defeat other players easily. In this problem you will be given a map as a 2D matrix and you have to find where the gold mines are.

输入

Input starts with an integer T (1 <= T <= 20), denoting the number of test cases. Each case starts with two integers R (3 ≤ R ≤ 100) denoting the number of rows in the matrix and C (3 ≤ C ≤ 100) denoting the number of columns in the matrix. The next R line will contain a line with characters to represent a row of the matrix. ‘#’ character means a rock, ‘*’ character means an empty field and ‘$’ means a gold mine.

输出

For each case of input, print the case number as “Case #:” and then output all the gold mine locations in the matrix, each in a separate line. The order or printing should consider the top left corner of the matrix first. The numbering of the row, column count should be 1 based indexing that is the first column of first row will be considered as (1, 1) and row number should be printed first then column number should be printed. If there is no gold found print one line without quotes “No Gold Found”.Please check the sample input/output for better understanding of the format.

输入样例 1

3
3 3
**#
*$*
###
4 3
*##
***
***
***
3 5
#####
*****
$***$

输出样例 1

Case 1:
2,2
Case 2:
No Gold Found
Case 3:
3,1
3,5

来源

Dev skill


代码

#include <cstdio>
#include <queue>
using namespace std;

struct Node{
    int x, y;
}f;

int main(){
    queue<Node> q;
    Node t1;
    int t, r, c, i;
    char matrix;
    scanf("%d", &t);
    for(i = 1; i <= t; i++){
        scanf("%d %d", &r, &c);
        for(f.y = 1; f.y <= r; f.y++){
            for(f.x = 1; f.x <= c; f.x++){
                if(f.x == 1) scanf("%*c%c", &matrix);
                else scanf("%c", &matrix);
                if(matrix == '$') q.push(f);
            }
        }
        printf("Case %d:\n", i);
        if(q.empty()) printf("No Gold Found\n");
        else{
            while(!q.empty()){
                t1 = q.front();
                q.pop();
                printf("%d,%d\n", t1.y, t1.x);
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_34072526/article/details/88220113
今日推荐