Problem
Chef is teaching a cooking course. There are students attending the course, numbered through .
Before each lesson, Chef has to take attendance, i.e. call out the names of students one by one and mark which students are present. Each student has a first name and a last name. In order to save time, Chef wants to call out only the first names of students. However, whenever there are multiple students with the same first name, Chef has to call out the full names (both first and last names) of all these students. For each student that does not share the first name with any other student, Chef may still call out only this student's first name.
Help Chef decide, for each student, whether he will call out this student's full name or only the first name.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- lines follow. For each valid , the -th of the following lines contains two space-separated strings denoting the first and last name of student .
Output
For each test case, print lines. For each valid , the -th of these lines should describe how Chef calls out the -th student's name ― it should contain either the first name or the first and last name separated by a space.
Constraints
- all first and last names contain only lowercase English letters
- the lengths of all first and last names are between and inclusive
Subtasks
Subtask #1 (100 points): original constraints
Sample 1:
1 4 hasan jaddouh farhod khakimiyon kerim kochekov hasan khateeb
hasan jaddouh farhod kerim hasan khateeb
Program :
#include <stdio.h>
#include<string.h>
int main(void) {
int t;
scanf("%d",&t);
while(t--)
{
int p;
scanf("%d",&p);
char s[p][50],s1[p][50];
for(int i=0;i<p;i++){
scanf("%s%s",s[i],s1[i]);
}
for(int i=0;i<p;i++){
int count=-1;
for(int j=0;j<p;j++){
if(strcmp(s[i],s[j])==0){
count++;
}
}
if(count>=1){
printf("%s %s\n",s[i],s1[i]);
}
else{
printf("%s\n",s[i]);
}
}
}
return 0;
}
0 Comments