Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- vector<string> vectorFiller(string str, char sep) {
- vector<string> v;
- string p = "";
- for (int i = 0; i < str.length(); i++) {
- if (str[i] == sep) {
- v.push_back(p);
- p = "";
- }
- else {
- p += str[i];
- }
- }
- v.push_back(p);
- return v;
- }
- int index(vector<string> v, string s) {
- for (int i = 0; i < v.size(); i++) {
- if (v[i] == s) {
- return i;
- }
- }
- return -1;
- }
- int main() {
- string line, product, newProduct, command;
- getline(cin, line);
- vector<string> list = vectorFiller(line, '!');
- while (true) {
- getline(cin, line);
- if (line == "Go Shopping!") {
- break;
- }
- vector<string> currentLine = vectorFiller(line, ' ');
- command = currentLine[0];
- product = currentLine[1];
- if (command == "Urgent" && index(list, product) == -1) {
- list.insert(list.begin(), product);
- }
- else if (command == "Unnecessary" && index(list, product) != -1) {
- list.erase(list.begin() + index(list, product));
- }
- else if (command == "Correct" && index(list, product) != -1) {
- newProduct = currentLine[2];
- list[index(list, product)] = newProduct;
- }
- else if (command == "Rearrange" && index(list, product) != -1) {
- list.erase(list.begin() + index(list, product));
- list.push_back(product);
- }
- }
- for (int i = 0; i < list.size() - 1; i++) {
- cout << list[i] << ", ";
- }
- cout << list[list.size() - 1] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement