Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- string input;
- getline(cin, input);
- vector<string> words;
- string current_word = "";
- for (int i = 0; i < input.length(); i++) {
- if (input[i] == ',' || input[i] == '.' || input[i] == ' ') {
- words.push_back(current_word);
- current_word = "";
- // Додаємо кому після кожного слова, крім останнього
- if (input[i] == ',') {
- words.push_back(", ");
- }
- }
- else {
- current_word += input[i];
- }
- }
- reverse(words.begin(), words.end());
- for (int i = 0; i < words.size(); i++) {
- // Додаємо крапку після останнього слова
- if (i == words.size() - 1) {
- cout << words[i] << ".";
- }
- else {
- cout << words[i];
- }
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment