Advertisement
zeushere

reverse string

Apr 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. #include <math.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8. string napis;
  9. void funkcja(string,int);
  10. int roz;
  11.  
  12. int main(){
  13. srand(time(0));
  14.  
  15. getline(cin,napis);
  16. cout<<endl;
  17. roz=napis.size();
  18. funkcja(napis,roz);
  19. return 0;
  20. }
  21.  
  22.  
  23. void funkcja(string s,int r)
  24. {
  25.     string reversee=s;
  26.     for(int i=0,j=(r-1);i<r;i++,j--)
  27.     {
  28.         if(s[i]==' ')
  29.         {
  30.             s[i]='_';
  31.         }
  32.         reversee[j]=s[i];
  33.  
  34.     }
  35.     cout<<reversee;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement