PTA 7-46 简易连连看(JAVA)

在这里插入图片描述
输入样例:

2
I T I T
Y T I A
T A T Y
I K K T
11
1 1 1 3
4 2 4 3
3 1 4 2
2 2 1 2
3 1 2 4
4 4 3 1
2 1 3 4
3 3 1 4
4 1 2 3
2 4 3 2
1 1 2 2

输出样例:

* T * T
Y T I A
T A T Y
I K K T
* T * T
Y T I A
T A T Y
I * * T
Uh-oh
* * * T
Y * I A
T A T Y
I * * T
Uh-oh
* * * T
Y * I A
* A T Y
I * * *
* * * T
* * I A
* A T *
I * * *
* * * *
* * I A
* A * *
I * * *
* * * *
* * * A
* A * *
* * * *
Congratulations!

JAVA代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    
    
    public static void main(String[] args) throws IOException{
    
    
        BufferedReader input=new BufferedReader(new InputStreamReader( System.in));
        String n=input.readLine();
        int x=Integer.parseInt(n);
        char [][] map=new char[2*x+1][2*x+1];
        for(int i=1;i<=2*x;i++)
        {
    
    
            String[] str=input.readLine().split(" ");
            for(int j=1;j<=2*x;j++)
            {
    
    
                map[i][j]=str[j-1].charAt(0);
            }
        }
        String m=input.readLine();
        int y=Integer.parseInt(m);
        int flag=0;
        int win=0;
        for(int i=1;i<=y;i++)
        {
    
    
            String[] str=input.readLine().split(" ");
            int [] index=new int[str.length];
            for(int j=0;j<str.length;j++)
                index[j]=Integer.parseInt(str[j]);
            if(map[index[0]][index[1]]==map[index[2]][index[3]]&&map[index[0]][index[1]]!='*')
            {
    
    
                win++;
                if(win*2==4*x*x)
                {
    
    
                    System.out.println("Congratulations!");
                    return;
                }
                map[index[0]][index[1]]='*';
                map[index[2]][index[3]]='*';
                for(int p=1;p<=2*x;p++)
                {
    
    
                    for(int q=1;q<=2*x;q++)
                    {
    
    
                        if(q!=2*x)
                            System.out.print(map[p][q]+" ");
                        else
                            System.out.print(map[p][q]);
                    }
                    System.out.println();
                }
            }
            else
            {
    
    
                System.out.println("Uh-oh");
                flag++;
                if(flag==3) {
    
    
                    System.out.println("Game Over");
                    return;
                }
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/m0_47470899/article/details/110005027