Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. string inverser_mot(string s)
  8. {
  9. int length = s.length();
  10. char c;
  11. int i = 0, j = length - 1;
  12.  
  13. for (; i < j; ++i, --j)
  14. {
  15. c = s.at(i);
  16. s.at(i) = s.at(j);
  17. s.at(j) = c;
  18. }
  19. return s;
  20. }
  21.  
  22. string inverser_lettres(string s)
  23. {
  24. int length = s.length();
  25. char c;
  26.  
  27. for (int i = 0; i < length; ++i)
  28. {
  29. if (!isspace(s.at(i)))
  30. {
  31. string toReplace = s.substr(i, s.find_first_of(' ', i) - i);
  32. i = i + toReplace.length()-1;
  33. s.replace(s.find(toReplace), toReplace.length(), inverser_mot(toReplace));
  34. }
  35. }
  36. return s;
  37. }
  38.  
  39. int main()
  40. {
  41. string s = " j'aime mon prof ";
  42. cout << s << endl;
  43. s = inverser_lettres(s);
  44. cout << s;
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement