fork download
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. #define MAX 300
  5.  
  6. int myStrcmp(char s1[], char s2[]);
  7. int myStrlen(char s[], int k);
  8. void myStrcpy(char s[], int vt, char s1[], int k);
  9. void mySubstr(char s[], int b, int count, char ss[]);
  10. bool myStrcat(char s1[], char s2[]);
  11. void StringReverse(char st[]);
  12.  
  13. int main()
  14. {
  15. char s[MAX];
  16. cin.getline(s,MAX);
  17. if (myStrcmp(s, "") == 0)
  18. cout << "Chuoi rong." << endl;
  19. else
  20. {
  21. StringReverse(s);
  22. cout << s << endl;
  23. }
  24. return 0;
  25. }
  26.  
  27. int myStrlen(char s[], int k){
  28. int dem = 0;
  29. for (int i=0;s[i]!='\0';i++) ++dem;
  30. return dem;
  31. }
  32.  
  33.  
  34. void rever(char s[],int st, int ed){
  35. //cout << st << " " << ed << endl;
  36. for (int i = 0 ; i<= (ed-st)/2 ; i++) {
  37. char temp = s[st+i];
  38. s[st+i] = s[ed-i];
  39. s[ed-i] = temp;
  40. }
  41. }
  42.  
  43.  
  44. void StringReverse(char s[]){
  45.  
  46.  
  47. int i = 0;
  48. while (i<myStrlen(s,0)){
  49. while (s[i]==' '&&i<myStrlen(s,0)) {
  50. //cout << s[i];
  51. ++i;
  52. }
  53. int strt = i;
  54. while (s[i]!=' '&&i<myStrlen(s,0)) ++i;
  55.  
  56. if (strt<myStrlen(s,0)){
  57.  
  58. if (i<myStrlen(s,0)) rever(s,strt,i-1);
  59. else rever(s,strt,myStrlen(s,0)-1);
  60. //cout << s << endl;
  61. }
  62.  
  63. }
  64.  
  65. }
  66.  
  67.  
  68. int myStrcmp(char s1[], char s2[]){
  69. bool check_space = false;
  70. if (myStrlen(s1,0)-1==0) return 0;
  71. //cout << myStrlen(s1,0) << endl;
  72. for (int i=0;i<myStrlen(s1,0)-1;i++) if (s1[i]!=' ') check_space=true;
  73. if (check_space==false) return 0; // chuoi toan dau cach
  74. return 1;
  75.  
  76. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Chuoi rong.