fork download
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. #define MAX 300
  5.  
  6. void ChenChuoiTaiVitriK(char s[], char s1[], int k);
  7. void Chuanhoa(char s[]);
  8. int myStrlen(char s[], int k);
  9. bool myStrcat(char s[], char s1[], char s2[]);
  10. void myStrcpy(char s[], int vt, char s1[], int k);
  11. int myStrstr(char s[], char s1[]);
  12.  
  13.  
  14. int main()
  15. {
  16. if(fopen("ben.inp", "r")){
  17. freopen("ben.inp", "r", stdin);
  18. freopen("ben.out", "w", stdout);
  19. }
  20. char s[MAX];
  21.  
  22. fflush(stdin);
  23. cin.getline(s, MAX);
  24.  
  25. char s1[MAX];
  26. myStrcpy(s1, 0, s, 0);
  27. Chuanhoa(s1);
  28. cout << s << endl << s1 << endl;
  29. return 0;
  30. }
  31.  
  32. //return length of string s start from s[k]
  33. int myStrlen(char s[], int k){
  34. int cnt = 0;
  35. while(s[k++] != '\0') cnt++;
  36. return cnt;
  37. }
  38.  
  39. //append string s2 to string s1
  40. bool myStrcat(char s[], char s1[], char s2[]){
  41. int len1 = myStrlen(s1, 0);
  42. int len2 = myStrlen(s2, 0);
  43. int len = len1 + len2;
  44. for(int i = 0; i < len1; i++){
  45. s[i] = s1[i];
  46. }
  47. for(int i = len1; i < len; i++){
  48. s[i] = s2[i - len1];
  49. }
  50. s[len] = '\0';
  51. return true;
  52. }
  53.  
  54. //create string s from string s1 start from s1[k]
  55. void myStrcpy(char s[], int vt, char s1[], int k){
  56. //s = s1[k...len - 1]
  57. int len = myStrlen(s1, k);
  58. for(int i = 0; i < len; i++){
  59. s[i] = s1[k + i];
  60. }
  61. s[len] = '\0';
  62. }
  63.  
  64. //return the first occurrence of string s1 in string s
  65. //return the size of string s if string s1 does not occur in string s
  66. int myStrstr(char s[], char s1[]){
  67. int n = myStrlen(s, 0);
  68. int m = myStrlen(s1, 0);
  69. for(int i = 0; i <= n - m; i++){
  70. bool satisfied = true;
  71. for(int j = i; j < i + m; j++){
  72. if(s[j] != s1[j - i]){
  73. satisfied = false;
  74. break;
  75. }
  76. }
  77. if(satisfied) return i;
  78. }
  79. return n;
  80. }
  81.  
  82. void Chuanhoa(char s[]){
  83. char dot[] = ".";
  84. int dot_pos = myStrstr(s, dot);
  85. int n = myStrlen(s, 0);
  86. int l, r;
  87.  
  88. char res[MAX];
  89.  
  90. while(dot_pos != n){
  91. l = r = dot_pos;
  92. while(l - 1 >= 0 && s[l - 1] == ' ') l--;
  93. while(r + 1 < n && s[r + 1] == ' ') r++;
  94.  
  95. char lt[MAX];
  96. myStrcpy(lt, 0, s, 0);
  97. lt[l] = '.';
  98. lt[l + 1] = '\0';
  99.  
  100. myStrcat(res, res, lt);
  101.  
  102. if(r + 1 == n) break;
  103.  
  104. myStrcat(res, res, " ");
  105.  
  106. myStrcpy(s, 0, s, r + 1);
  107.  
  108. dot_pos = myStrstr(s, dot);
  109. n = myStrlen(s, 0);
  110. }
  111.  
  112. myStrcpy(s, 0, res, 0);
  113. }
  114.  
  115.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout