Advertisement
J00ker

Untitled

Jan 13th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. void Citire(char *s)
  8. {
  9. ifstream fin("text.in");
  10. fin.getline(s, 999);
  11. fin.close();
  12. }
  13.  
  14. void Replace(char *text, char c1, char c2)
  15. {
  16. for(int i = 0; text[i] != 0; i++)
  17. if(text[i] == c1) text[i] = c2;
  18. }
  19.  
  20. void Delete(char *text)
  21. {
  22. char *p;
  23. while((p = strstr(text, " ")) != NULL)
  24. strcpy(p+1, p+2);
  25. }
  26.  
  27. void Trim(char *text)
  28. {
  29. int i;
  30. for(i = 0; text[i] == ' '; i++);
  31. strcpy(text, text+i);
  32.  
  33. for(i = strlen(text)-1; text[i] == ' '; i--);
  34. text[i+1] = 0;
  35. }
  36.  
  37. int Count(char *text)
  38. {
  39. int nr = 0;
  40. for(int i = 0; text[i] != 0; i++)
  41. if(text[i] == ' ') nr++;
  42. return nr+1;
  43. }
  44.  
  45. void Solve(char *text)
  46. {
  47. char sep[] = ".,?!;:";
  48. for(int i = 0; i < 6; i++)
  49. Replace(text, sep[i], ' ');
  50. Trim(text);
  51. Delete(text);
  52. cout << Count(text);
  53. }
  54.  
  55. int main()
  56. {
  57. char text[1000];
  58. Citire(text);
  59. //Replace(text, 'a', 'x');
  60. //cout << text << "\n";
  61. //Delete(text);
  62. //cout << text << "\n";
  63. //cin.getline(text, 999);
  64. cout << text << "\n";
  65. //Trim(text);
  66. //cout << text << "." << "\n";
  67. //cout << Count(text) << "\n";
  68. Solve(text);
  69. //cout << text << "\n";
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement