Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- string s = "kitten in a cup";
- cout << "start line: " << s;
- int j = -1;
- for (int i = 0; i < s.length(); ++i) {
- if (s[i] == 'k') {
- s[i] = 'c';
- j = i;
- break;
- }
- if (i + 1 == s.length()) {
- cout << endl << "there is no 'k' in the initial line";
- }
- }
- for (int i = s.length(); i > 0; i--) {
- if (s[i] == 'c' && i != j) {
- s[i] = 'k';
- break;
- }
- if (i - 1 == 0) {
- cout << endl << "there is no 'c' in the initial line";
- }
- }
- cout << endl << "processed string: " << s;
- }
Advertisement
Add Comment
Please, Sign In to add comment