Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- string inverser_mot(string s)
- {
- int length = s.length();
- char c;
- int i = 0, j = length - 1;
- for (; i < j; ++i, --j)
- {
- c = s.at(i);
- s.at(i) = s.at(j);
- s.at(j) = c;
- }
- return s;
- }
- string inverser_lettres(string s)
- {
- int length = s.length();
- char c;
- for (int i = 0; i < length; ++i)
- {
- if (!isspace(s.at(i)))
- {
- string toReplace = s.substr(i, s.find_first_of(' ', i) - i);
- i = i + toReplace.length()-1;
- s.replace(s.find(toReplace), toReplace.length(), inverser_mot(toReplace));
- }
- }
- return s;
- }
- int main()
- {
- string s = " j'aime mon prof ";
- cout << s << endl;
- s = inverser_lettres(s);
- cout << s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement