HDACM2094
思路:把没有输过的选手名字字符串数组保存起来,然后在去字符串中找如果出现两个或者多个不同的选手名字或者一个都没有则没有冠军产生,只有字符串数组中只有一个相同的名字是采用冠军产生。
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
if (n==0) {
break;
}
String[][] str = new String[n][2];
for (int i = 0; i < n; i++) {
str[i][0]=sc.next();
str[i][1]=sc.next();
}
String[] s = new String[n];
for (int i = 0; i < str.length; i++) {
for (int j = 0; j < str.length; j++) {
if (str[i][0].equals(str[j][1])) {
break;
}
if (j==str.length-1) {
s[i] = str[i][0];
}
}
}
boolean boo = false;
int pos = -1;
for (int i = 0; i < s.length; i++) {
if (s[i]==null) {
continue;
}
if (!boo) {
boo = true;
pos = i;
}
if (!s[pos].equals(s[i])) {
boo = false;
break;
}
}
if (!boo) {
System.out.println("No");
continue;
}
System.out.println("Yes");
}
}
}