Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main() {
- string message, command;
- getline(cin, message);
- while (true) {
- getline(cin, command);
- if (command == "Decode") {
- break;
- }
- vector<string> tokens;
- for (int i = 0; i < command.length(); i++) {
- if (command[i] == '|') {
- string token = command.substr(0, i);
- tokens.push_back(token);
- command = command.erase(0, token.length() + 1);
- i = 0;
- }
- }
- tokens.push_back(command);
- command = tokens[0];
- if (command == "Move") {
- int index = stoi(tokens[1]);
- string subStr = message.substr(0, index);
- message.erase(0, index);
- message += subStr;
- }
- else if (command == "Insert") {
- int index = stoi(tokens[1]);
- string value = tokens[2];
- message = message.insert(index, value);
- }
- else if (command == "ChangeAll") {
- string oldStr = tokens[1];
- string newStr = tokens[2];
- while (message.find(oldStr) != -1) {
- message.replace(message.find(oldStr), oldStr.length(), newStr);
- }
- }
- }
- cout << "The decrypted message is: " << message << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement