vlatkovski

Cokolado

Sep 16th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string s;
  8.     char c;
  9.     cin >> s >> c;
  10.  
  11.     int n = 0, len = s.length();
  12.  
  13.     for (int i = 0; i < len; ++i) {
  14.         char x = s.at(i);
  15.  
  16.         if (x == c) {
  17.             if (i - 1 >= 0 && s.at(i - 1) != x) {
  18.                 n++;
  19.             }
  20.             if (i + 1 < len && s.at(i + 1) != x) {
  21.                 n++;
  22.             }
  23.         }
  24.     }
  25.  
  26.     cout << n << endl;
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment