Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <iterator>
- #include <string>
- using namespace std;
- void my_reverse(string& s, int c = 0) {
- if (!c) c = (int) s.size() - 1;
- for (int i = 0, j = c; i < j; i++, j--) {
- char t = s[i];
- s[i] = s[j];
- s[j] = t;
- }
- }
- int main() {
- string s1 = "This is a test.";
- string s2 = "I like C++.";
- string s3 = s1;
- string s4 = s2;
- my_reverse(s1);
- my_reverse(s2, 7);
- reverse(s3.begin(), s3.end());
- reverse(s4.begin(), s4.begin() + 7 + 1);
- cout << s1 << endl;
- cout << s2 << endl;
- cout << s3 << endl;
- cout << s4 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement