Advertisement
J00ker

./

Jan 7th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. inline void Citire(char* s)
  9. {
  10. ifstream fin("text.in");
  11. fin.getline(s, 999);
  12. fin.close();
  13. }
  14.  
  15. int main()
  16. {
  17. char s[1001], *p;
  18. Citire(s);
  19. cout << s << "\n\n\n";
  20.  
  21. //a
  22. int nrcuv = 0;
  23. p = strtok(s, " ");
  24. while(p != NULL)
  25. {
  26. nrcuv++;
  27. p = strtok(NULL, " ");
  28. }
  29. cout << "a)Nr. cuvinte: " << nrcuv << "\n\n";
  30. /*
  31. while((p = strchr(s, ' ')) != NULL)
  32. {
  33. n++;
  34. strcpy(p, p+1);
  35. }
  36. cout << n+1;
  37. */
  38.  
  39. //b
  40. Citire(s);
  41. int mx = 0, len = 0;
  42. p = strtok(s, " ");
  43. while(p != NULL)
  44. {
  45. len = strlen(p);
  46. if(len > mx) mx = len;
  47. p = strtok(NULL, " ");
  48. }
  49. cout << "b)Lung. max. a unui cuvant: " << mx << "\n\n";
  50.  
  51. //c
  52. Citire(s);
  53. int apr = 0;
  54. while((p = strstr(s, "muschi")) != NULL)
  55. {
  56. apr++;
  57. strcpy(p, p+6);
  58. }
  59. cout << "c)\"Muschi\" aparitii: " << apr << "\n\n";
  60.  
  61. //d
  62. Citire(s);
  63. char cuv[nrcuv][100];
  64. char a[100], b[100];
  65. int i = 0, j;
  66. p = strtok(s, " ");
  67. while(p != NULL)
  68. {
  69. strcpy(cuv[i], p); i++;
  70. p = strtok(NULL, " ");
  71. }
  72.  
  73. for(i = 0; i+1 < nrcuv; i++)
  74. for(j = i+1; j < nrcuv; j++)
  75. {
  76. strcpy(a, cuv[i]);
  77. strcpy(b, cuv[j]);
  78. int x = strcmp(a, b);
  79. if(x > 0)
  80. {
  81. strcpy(cuv[i], cuv[j]);
  82. strcpy(cuv[j], a);
  83. }
  84. }
  85. cout << "d)Cuvintele ordonate alfabetic:\n";
  86. for(i = 0; i < nrcuv; i++)
  87. cout << cuv[i] << " " ;
  88. cout << "\n\n";
  89.  
  90. //d
  91. Citire(s);
  92. for(i = 0; s[i] != 0; i++)
  93. if(s[i] != 32) s[i] -= 32;
  94. cout << "e)Uppercase: " << s;
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement