fork download
  1. #include <bits/stdc++.h>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n, count = 0;
  9. //string chl;
  10. char temp;
  11. scanf("%d",&n);
  12. while(n--)
  13. {
  14.  
  15. //printf("A\n");
  16. int i,p,q;
  17. //cin.ignore( 256, '\n') ;
  18. //getline(cin,chl);
  19. char chl[1000];
  20. //cin>>chl;
  21. scanf("%c",&temp); // temp statement to clear buffer
  22. scanf("%[^\n]",chl);
  23.  
  24. for (i = 0; chl[i] != '\0';i++ )
  25. {
  26. //printf("BB");
  27. //printf("%c\n",chl[i]);
  28. /* code */
  29. if (chl[i] == ' ')
  30. {
  31. p = i-1;
  32. while(chl[p] != ' ' && p>=0)
  33. printf("%c",chl[p--]);
  34. printf(" ");
  35. }
  36. //scanf("%c",&ch[++i]);
  37. }
  38. while(chl[i] == '\0' && chl[i] != ' ')
  39. {
  40. i = i-1;
  41. while(chl[i] != ' ' && i>=0)
  42. printf("%c",chl[i--]);
  43. printf("\n");
  44. }
  45. }
  46. //printf("AA\n");
  47. return 0;
  48. }
Success #stdin #stdout 0s 4284KB
stdin
3
this is a test
foo bar
i love CS
stdout
siht si a tset
oof rab
i evol SC