Skip to content

Instantly share code, notes, and snippets.

@ushitora-anqou
Created March 30, 2019 14:56
Show Gist options
  • Save ushitora-anqou/6451a5f501444abe5061cc8fc274e563 to your computer and use it in GitHub Desktop.
Save ushitora-anqou/6451a5f501444abe5061cc8fc274e563 to your computer and use it in GitHub Desktop.
#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