# Attendance Codechef Solution

#### ByBrokenprogrammers

Dec 20, 2022

Hello Programmers In this post, you will know how to solve the Attendance Codechef Solution. The Problem Code: ATTND

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

### Problem

Chef is teaching a cooking course. There are N students attending the course, numbered 1 through N.

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 T denoting the number of test cases. The description of T test cases follows.
• The first line of each test case contains a single integer N.
• N lines follow. For each valid i, the ii-th of the following N lines contains two space-separated strings denoting the first and last name of student i.

### Output

For each test case, print N lines. For each valid ii, the i-th of these lines should describe how Chef calls out the i-th student’s name ― it should contain either the first name or the first and last name separated by a space.

### Constraints

• 1≤T≤1001≤T≤100
• 2≤N≤1002≤N≤100
• all first and last names contain only lowercase English letters
• the lengths of all first and last names are between 1 and 10 inclusive

### Sample Input 1

``````1
4
farhod khakimiyon
kerim kochekov
hasan khateeb``````

### Sample Output 1

```hasan jaddouh
farhod
kerim
hasan khateeb```

### Attendance CodeChef Solution in JAVA

```import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 0; tc < T; tc++) {
int N = sc.nextInt();
String[] firstNames = new String[N];
String[] lastNames = new String[N];
for (int i = 0; i < N; i++) {
firstNames[i] = sc.next();
lastNames[i] = sc.next();
}
System.out.print(solve(firstNames, lastNames));
}
sc.close();
}
static String solve(String[] firstNames, String[] lastNames) {
Map<String, Integer> firstNameToCount = new HashMap<>();
for (String firstName : firstNames) {
firstNameToCount.put(firstName, firstNameToCount.getOrDefault(firstName, 0) + 1);
}
StringBuilder result = new StringBuilder();
for (int i = 0; i < firstNames.length; i++) {
result.append(firstNames[i]);
if (firstNameToCount.get(firstNames[i]) != 1) {
result.append(" ").append(lastNames[i]);
}
result.append("\n");
}
return result.toString();
}
}```

### Attendance CodeChef Solution in CPP

```#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string arr1[n];
string arr2[n];
for(int i=0;i<n;i++){
cin>>arr1[i]>>arr2[i];
}
for(int i=0;i<n;i++){
int c=0;
for(int j=0;j<n;j++){
if(j!=i){
if(arr1[i]==arr1[j]){
cout<<arr1[i]<<" "<<arr2[i]<<endl;
c++;
break;
}
}
}
if(c==0){
cout<<arr1[i]<<endl;
}
}
}
return 0;
}
```

### Attendance CodeChef Solution in Python

```t = int(input())
for i in range(t):
n = int(input())
d = []
e = []
for i in range(n):
a, b = map(str, input().split())
d.append(a)
e.append(b)
for i in range(n):
if d.count(d[i])>1:
print(d[i], e[i])
else:
print(d[i])```

Disclaimer: The above Problem (Attendance) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.