Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <list>
- using namespace std;
- list<int> split(string str) {
- getline(cin, str);
- istringstream s(str);
- list<int> numbers;
- int n;
- while (s >> n) {
- numbers.push_back(n);
- }
- return numbers;
- }
- int main() {
- string line, wagon, listMergeVagons;
- list<int> trackA = split(line);
- list<int> trackB = split(line);
- list<int> vagonsMerge;
- while (trackA.size() + trackB.size() != 0) {
- wagon = trackA.empty() ? "B" :
- trackB.empty() ? "A" :
- (trackA.back() < trackB.back() ? "A" : "B");
- vagonsMerge.push_front(wagon == "A" ? trackA.back() : trackB.back());
- wagon == "A" ? trackA.pop_back() : trackB.pop_back();
- listMergeVagons += wagon;
- }
- cout << listMergeVagons << endl;
- for (auto& w : vagonsMerge) {
- cout << w << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement