-
Title Description:
-
There are a group of people, playing table tennis games, 22 catch to kill, every two people play a maximum of a game.
The rules of the game are as follows:
If a defeated B,b and defeated C, and A and C did not play, then it is decided that a must be able to defeat C.
If a defeated B,b and defeated C, and C defeated A, then a, B, C Three will not be the champion.
According to this rule, there is no need to cycle a contest, perhaps to determine the championship. Your task is to face a group of contestants, after a number of killings, to determine whether it has actually produced a championship.
-
Input:
-
The input contains a number of contestants, each of which starts with an integer n (n<1000) followed by N against the competitor, and the result is given by a pair of player names (one space between them), the former defeating the latter. If n is 0, it indicates the end of the input.
-
Output:
-
For each player group, if you determine that a winner is generated, output "Yes" in one row, otherwise output "No" in a row.
-
Sample input:
-
3Alice bobsmith Johnalice smith5a CC dd EB ea d0
Sample output:
Yes
No
Idea: Yes if there is only one vertex in all vertices with zero in degrees;
The code is as follows:
#include <stdio.h>
#include <string.h>
#define N 1001
struct Node {
Char name[100];
int indegree;
}nodes[n];
int main () {
int n;
while (scanf ("%d", &n)! = EOF && n! = 0) {
Char str1[100];
Char str2[100];
int count = 0;
for (int i = 0; i < n; i++) {
scanf ("%s%s", STR1,STR2);
int f1 = 0,F2 = 0;//f1 represents the winner, F2 represents the loser
for (int j = 0; J < Count; J + +) {
if (strcmp (str1,nodes[j].name) = = 0) {
F1 = 1;
}
if (strcmp (str2,nodes[j].name) = = 0) {
NODES[J]. indegree++;
F2 = 1;
Break
}
}
if (F1 = = 0) {//The player does not exist
strcpy (NODES[COUNT].NAME,STR1);//Save the player information
nodes[count++]. Indegree = 0;
}
if (F2 = = 0) {
strcpy (NODES[COUNT].NAME,STR2);
nodes[count++]. Indegree = 1;
}
}
int ans = 0;
for (int i = 0; i < count; i++) {
if (Nodes[i]. Indegree = = 0) {
ans++;
}
}
if (ans = = 1) {
printf ("yes\n");
}else{
printf ("no\n");
}
}
}
Nine degree title 1450: produce the Championship