Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string removeExtraSpaces(const string& input) {
- string result;
- bool spaceFound = false;
- for (char c : input) {
- if (c != ' ') {
- result += c;
- spaceFound = false;
- } else if (!spaceFound) {
- result += c;
- spaceFound = true;
- }
- }
- return result;
- }
- int main() {
- string str;
- cout << "Введіть рядок: ";
- getline(cin, str);
- string cleanedStr = removeExtraSpaces(str);
- cout << "Рядок після видалення зайвих пробілів: \"" << cleanedStr << "\"" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment