-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJoinStringTest.cpp
66 lines (48 loc) · 1.31 KB
/
JoinStringTest.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
int main(void){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
cin.get(); // important to input correct number of n values
list <string> s[n]; //declare list like this
// Another way to input data into list
// list <string> s;
// for(int i=0; i<n; i++){
// string individual;
//
// cin >> individual;
//
// s.push_back(individual);
//
// //getline(cin,individual);
//
// //cout << individual; //print out after n values taken in
//
// }
for(int i=0; i<n; i++){
string individual;
cin >> individual;
s[i].push_back(individual);
//getline(cin,individual);
//cout << individual; //print out after n values taken in
}
--n; // to change to n-1 and start from 0 index
int a=0;
int b=0;
while(n != 0){
cin >> a >> b; //input the numbers
--a; //important work in 0 based index
--b; //important
s[a].splice(s[a].end(),s[b]); //transfer all the elements from b to end of a.
//s[a].splice(s[a].begin(),s[b]); transfer all the elements from b to front of a
n--;
}
//To display
for (auto &v : s[a]){ // display string pointing to s[a] eg. s[2] for 1st test case (like a pointer)
cout << v;
}
cout << endl;
return 0;
}