Advertisement
Dan38zzzz

chuỗi

Dec 28th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<ctype.h>
  4. #include<string>
  5. void nhapchuoi(char s[])
  6. {
  7. printf("\nnhap chuoi:");
  8. gets(s);
  9. }
  10. void xuatchuoi(char s[])
  11. {
  12. printf("\nxuat chuoi:");
  13. puts(s);
  14. }
  15. void demkt(char s[])
  16. {
  17. int dem = 0;
  18. for (int i = 0; i < strlen(s); i++)
  19. {
  20. if (s[i] == ' ')
  21. dem++;
  22. }
  23. if (dem != 0)
  24. printf("\nchuoi co %d khoang trang", dem);
  25. else
  26. printf("chuoi khong co khoang trang");
  27. }
  28. void xoathua(char s[])
  29. {
  30. while (strstr(s, " "))
  31. {
  32. if (s[0] == ' ')
  33. s[0] = s[1];
  34. else
  35. {
  36. for (int i = 0; i < strlen(s); i++)
  37. {
  38. if (s[i] == ' '&&s[i + 1] == ' ')
  39. {
  40. for (int j = i + 1; j < strlen(s) - 1; j++)
  41. s[j] = s[j + 1];
  42. s[strlen(s) - 1] = '\0';
  43. }
  44. }
  45. }
  46. }
  47. xuatchuoi(s);
  48. }
  49. void main()
  50. {
  51. char s[100];
  52. nhapchuoi(s);
  53. xuatchuoi(s);
  54. demkt(s);
  55. xoathua(s);
  56. getch();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement