Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- string input, word, message;
- cin >> input;
- int c = 0, o = 0, n = 0;
- while (input != "End") {
- char letter = input[0];
- if (letter >= 'A' && letter <= 'Z' || letter >= 'a' && letter <= 'z') {
- if (letter == 'c' && c == 0) {
- c++;
- }
- else if (letter == 'o' && o == 0) {
- o++;
- }
- else if (letter == 'n' && n == 0) {
- n++;
- }
- else {
- word += letter;
- }
- if (c == 1 && o == 1 && n == 1) {
- c--; o--; n--;
- message += " " + word;
- word = "";
- }
- }
- cin >> input;
- }
- cout << message << endl;
- return 0;
- }
- Решение с find(), replace() и isalpha():
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string input, word, message, secretWord = "con";
- cin >> input;
- while (input != "End") {
- char letter = input[0];
- if (secretWord.find(letter) != -1) {
- secretWord.replace(secretWord.find(letter), 1, "");
- if (secretWord == "") {
- secretWord = "con";
- message += word + " ";
- word = "";
- }
- }
- else if (isalpha(letter)) {
- word += letter;
- }
- cin >> input;
- }
- cout << message << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement