x2311

Untitled

Dec 21st, 2021
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string s = "kitten in a cup";
  7.     cout << "start line: " << s;
  8.     int j = -1;
  9.     for (int i = 0; i < s.length(); ++i) {
  10.         if (s[i] == 'k') {
  11.             s[i] = 'c';
  12.             j = i;
  13.             break;
  14.         }
  15.         if (i + 1 == s.length()) {
  16.             cout << endl << "there is no 'k' in the initial line";
  17.         }
  18.     }
  19.     for (int i = s.length(); i > 0; i--) {
  20.         if (s[i] == 'c' && i != j) {
  21.             s[i] = 'k';
  22.             break;
  23.         }
  24.         if (i - 1 == 0) {
  25.             cout << endl << "there is no 'c' in the initial line";
  26.         }
  27.     }
  28.     cout << endl << "processed string: " << s;
  29.  
  30. }
  31.  
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment