Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- //функция считывает слово из строки,
- //номер n указывает на начало слова,
- //после выхода из функции - на конец слова
- string read_word(string s, int &i)
- {
- //в слове могут быть только буквы и дефис
- string word;
- while (isalpha(s[i]) || s[i] == '-') { word += s[i]; ++i; }
- return word;
- }
- int main()
- {
- string s;
- getline(cin, s);
- for (int i = 0; i < s.size(); ++i)
- if (isalpha(s[i]))
- {
- string word = read_word(s, i); word[0] = (char)tolower(word[0]);
- bool c = 0; //0 - повторяющихся слов не нашлось, 1 - противный случай
- for (int j = i; j < s.size(); ++j)
- if (isalpha(s[j]))
- {
- string w = read_word(s, j); w[0] = (char)tolower(w[0]);
- if (w == word) { s.erase(j - w.size() , w.size() ); c = 1; }
- }
- if (c) s.erase( i - word.size() , word.size() );
- i -= word.size();
- }
- cout << s << endl;
- return 0;
- }
- //input1: One, two, Three, four, Five, six, Two, Four, Six, three, six.
- //output1: One, , , , Five, , , , , , .
- //input2: Hello, world! Hello, world, again...
- //output2: , ! , , again...
Add Comment
Please, Sign In to add comment