Created
March 30, 2019 14:56
-
-
Save ushitora-anqou/6451a5f501444abe5061cc8fc274e563 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <optional> | |
int main() | |
{ | |
std::string input; | |
while (std::getline(std::cin, input)) { | |
std::optional<int> begin, end; | |
for (int i = 0; i < input.size(); i++) { | |
char ch = input[i]; | |
if (ch != '"') continue; | |
if (!begin) { | |
begin = i; | |
continue; | |
} | |
end = i; | |
break; | |
} | |
if (!begin || !end) { | |
std::cout << input << std::endl; | |
continue; | |
} | |
std::cout << input.substr(0, *begin) << "\"\\" << std::endl; | |
for (int i = *begin + 1; i < *end; i++) | |
std::cout << input[i] << "\\" << std::endl; | |
std::cout << "\"" << input.substr(*end + 1) << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment