MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

CodeChef_problems/ATTND/solution.cpp:9–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7using namespace std;
8
9int main() {
10 ios_base::sync_with_stdio(false); // Speeds up the execution time
11 cin.tie(NULL);
12
13 lli t; // number of test cases
14 cin >> t;
15
16 while(t--) {
17 lli n;
18 cin >> n;
19
20 // save first name and last name in different arrays
21 vector<string> first(n);
22 vector<string> last(n);
23
24 for(lli i = 0; i < n; i++) {
25 cin >> first[i] >> last[i];
26 }
27
28 vector<bool> callOnlyFirstName(n, true);
29
30 // check if first name of one student matches with any other student's first name.
31 for(lli i = 0; i < n - 1; i++) {
32 if(callOnlyFirstName[i] != false) {
33 for(lli j = i + 1; j < n; j++) {
34 if(first[i] == first[j]) {
35 callOnlyFirstName[i] = false;
36 callOnlyFirstName[j] = false;
37 }
38 }
39 }
40 }
41
42 // Output first & lastname for students having same first name and print only first name for all others.
43 for(lli i = 0; i < n; i++){
44 if(callOnlyFirstName[i]) {
45 cout << first[i] << endl;
46 } else {
47 cout << first[i] << " " << last[i] << endl;
48 }
49 }
50 }
51
52 return 0;
53}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected