Vla_DOS

12.3

Feb 20th, 2023
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string input;
  10.     getline(cin, input);
  11.  
  12.     vector<string> words;
  13.     string current_word = "";
  14.  
  15.     for (int i = 0; i < input.length(); i++) {
  16.         if (input[i] == ',' || input[i] == '.' || input[i] == ' ') {
  17.             words.push_back(current_word);
  18.             current_word = "";
  19.  
  20.             // Додаємо кому після кожного слова, крім останнього
  21.             if (input[i] == ',') {
  22.                 words.push_back(", ");
  23.             }
  24.         }
  25.         else {
  26.             current_word += input[i];
  27.         }
  28.     }
  29.     reverse(words.begin(), words.end());
  30.  
  31.     for (int i = 0; i < words.size(); i++) {
  32.         // Додаємо крапку після останнього слова
  33.         if (i == words.size() - 1) {
  34.             cout << words[i] << ".";
  35.         }
  36.         else {
  37.             cout << words[i];
  38.         }
  39.     }
  40.  
  41.     cout << endl;
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment