29 lines
809 B
C++
29 lines
809 B
C++
#include <algorithm>
|
|
#include <iostream>
|
|
#include <limits>
|
|
|
|
|
|
int main() {
|
|
|
|
std::cout << "Enter To-Minify: \n"
|
|
"Press Ctrl+d (Unix) or Ctrl+z followed by Enter on a new line (Windows) to confirm input\n"
|
|
"Press Ctrl+c or enter an empty string to exit" << std::endl;
|
|
|
|
std::string input;
|
|
std::getline(std::cin, input, static_cast<char>(EOF));
|
|
std::cin.clear();
|
|
|
|
if (input.empty())
|
|
return 0;
|
|
|
|
std::replace_if(input.begin(), input.end(), [] (char c) { return isspace(c); }, ' ');
|
|
|
|
std::string output;
|
|
std::unique_copy(input.begin(), input.end(), std::back_insert_iterator<std::string>(output),
|
|
[](char i, char in){ return std::isspace(i) && std::isspace(in); });
|
|
|
|
std::cout << "----------------------------------------\n";
|
|
std::cout << output << "\n" << std::endl;
|
|
|
|
return 0;
|
|
} |