fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. void trimRight (char * str) { *--find_if (make_reverse_iterator (str + strlen (str)), make_reverse_iterator (str), [] (char cur) {return cur != ' '; }) = '\0'; }
  9.  
  10. int main (int argc, char *argv [])
  11. {
  12. char s [8193];
  13. scanf ("%8192[ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]", s);
  14. printf ("%s:\n%s.\n", "Original string", s);
  15. trimRight (s);
  16. printf ("%s:\n%s.\n", "Trimmed string", s);
  17. return 0;
  18. }
Success #stdin #stdout 0s 3464KB
stdin
a b 
stdout
Original string:
a b .
Trimmed string:
a b.