Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <list>
- using namespace std;
- void showlist(list <int> out)
- {
- list<int>::iterator it;
- for (it = out.begin(); it != out.end(); ++it)
- {
- cout << *it << ' ';
- }
- }
- int main()
- {
- int numberOfCommands;
- cin >> numberOfCommands;
- cin.ignore();
- list<int> glass, metal, plastic;
- for (int i = 1; i <= numberOfCommands; i++)
- {
- string input;
- getline(cin, input);
- istringstream istr(input);
- string line, command;
- istr >> line >> command;
- if (line == "glass")
- {
- if (command == "front")
- {
- glass.push_front(i);
- }
- else
- {
- glass.push_back(i);
- }
- }
- else if (line == "metal")
- {
- if (command == "front")
- {
- metal.push_front(i);
- }
- else
- {
- metal.push_back(i);
- }
- }
- else if (line == "plastic")
- {
- if (command == "front")
- {
- plastic.push_front(i);
- }
- else
- {
- plastic.push_back(i);
- }
- }
- else
- {
- i -= 1;
- --numberOfCommands;
- }
- }
- if (!glass.empty())
- {
- cout << "glass - ";
- showlist(glass);
- cout << endl;
- }
- if (!metal.empty())
- {
- cout << "metal - ";
- showlist(metal);
- cout << endl;
- }
- if (!plastic.empty())
- {
- cout << "plastic - ";
- showlist(plastic);
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment