Advertisement
kokokozhina

string_II_10

Dec 28th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     setlocale(LC_ALL, "Russian");
  9.  
  10.     int n = 0;
  11.     char c;
  12.  
  13.     string s;
  14.     cout << "Введите строку так, чтобы какая-либо буква встречалась ровно два раза:" << endl ;
  15.     cin >> s;
  16.    
  17.     for(int i = 0; i < s.length() - 1; i++ )
  18.     {
  19.         for(int j = i+1; j < s.length(); j++)
  20.             if(s[j] == s[i])
  21.             {
  22.                 n++;
  23.                 c = s[i];
  24.             }
  25.  
  26.             if(n > 1)
  27.                 break;
  28.     }
  29.  
  30.     if (n == 1)
  31.         cout << "Буква " << c << " встречается ровно два раза" << endl;
  32.     else cout << "Ошибка. Попробуйте ввести слово еще раз" << endl;
  33.  
  34.     cout << endl;
  35.  
  36.     system("pause");
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement