题目解析
给定每个人头上的帽子
再给k组 每个人猜测的答案
如果所有人都猜对了或者只有一个人回答且猜对了,
则输出 Da Jiang!!!
否则输出 Ai Ya
解题思路
if判断
输出...
代码
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String[] args) throws IOException
{
int n = sc.nextInt();
int shu[] = new int[n + 10]; // 每个人头上帽子的颜色
for (int i = 1; i <= n; i++)
shu[i] = sc.nextInt();
int k = sc.nextInt();
while (k-- > 0)
{
int a = 0; // 猜对的人数
int b = 0; // 猜错的人数
for (int i = 1; i <= n; i++)
{
int x = sc.nextInt();
if (x == shu[i])
a++;
else if (x != 0) // 猜错了
b++;
}
if (b == 0 && a > 0)
out.println("Da Jiang!!!");
else
out.println("Ai Ya");
}
out.flush();
out.close();
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
}