-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMishaandChangingHandles.cpp
More file actions
48 lines (39 loc) · 1.16 KB
/
MishaandChangingHandles.cpp
File metadata and controls
48 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <cstdio>
#include <utility>
#include <string>
#include <vector>
using namespace std;
bool check[1001] = {false,};
int main() {
int n;
scanf("%d", &n);
vector<pair<string, string> > handleChangeLog(n);
string oldHandle, newHandle;
for(int i = 0; i < n; i++) {
cin >> oldHandle >> newHandle;
handleChangeLog[i] = make_pair(oldHandle ,newHandle);
}
vector<pair<string, string> > result;
for(int i = 0; i < n; i++) {
if(check[i]) continue;
pair<string, string> ele = handleChangeLog[i];
string searchString = ele.second;
check[i] = true;
for(int j = i + 1; j < n; j++) {
if(check[j]) continue;
if(searchString.compare(handleChangeLog[j].first) == 0) {
check[j] = true;
ele.second = handleChangeLog[j].second;
searchString = handleChangeLog[j].second;
}
}
result.push_back(ele);
}
int len = result.size();
printf("%d\n", len);
for(int i = 0; i < len; i++) {
cout << result[i].first << " " << result[i].second << '\n';
}
return 0;
}