Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n = 0;
- char c;
- string s;
- cout << "Введите строку так, чтобы какая-либо буква встречалась ровно два раза:" << endl ;
- cin >> s;
- for(int i = 0; i < s.length() - 1; i++ )
- {
- for(int j = i+1; j < s.length(); j++)
- if(s[j] == s[i])
- {
- n++;
- c = s[i];
- }
- if(n > 1)
- break;
- }
- if (n == 1)
- cout << "Буква " << c << " встречается ровно два раза" << endl;
- else cout << "Ошибка. Попробуйте ввести слово еще раз" << endl;
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement