Advertisement
jelyslime

Untitled

Jan 28th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. char mostMet(char* sub, char* stringMnoj, int* counters, int sizeOfSub, int sizeOfString)
  7. {
  8. int poz = 0;
  9. int tempBiggest = 0;
  10.  
  11.  
  12. for (int j = 0; j < strlen(stringMnoj); j++) {
  13. for (int k = 0; k < strlen(sub); k++) {
  14.  
  15. if (sub[k] == stringMnoj[j])
  16. {
  17. counters[k] = counters[k] + 1;
  18. continue;
  19. }
  20. }
  21. }
  22.  
  23.  
  24. for (int i = 0; i < sizeOfSub; i++)
  25. {
  26. if (counters[i] > tempBiggest)
  27. {
  28. tempBiggest = counters[i];
  29. poz = i;
  30. }
  31. }
  32.  
  33. for (int i = 0; i < sizeOfSub; i++)
  34. {
  35. if (sub[i] == sub[poz])
  36. {
  37. sub[i] == '!';
  38. }
  39. }
  40.  
  41. return sub[poz];
  42.  
  43. }
  44.  
  45. void changeString(char* stringToChange, int stringSize, char mostMetChar)
  46. {
  47. for (int i = 0; i < stringSize; i++)
  48. {
  49. if (stringToChange[i] == mostMetChar) {
  50. stringToChange[i] = '!';
  51. }
  52. }
  53. cout << stringToChange;
  54. }
  55.  
  56.  
  57.  
  58. int main()
  59. {
  60.  
  61.  
  62.  
  63. char subMnoj[] = { 't','m','o','e','\0' };
  64. char stringMnoj[] = { "This is a test string!" };
  65.  
  66. cout << "Mnojestvo: " << endl;
  67. for (int i = 0; i < strlen(stringMnoj); i++) {
  68. if (subMnoj[i] == '\0')
  69. {
  70. break;
  71. }
  72. cout << subMnoj[i];
  73.  
  74. }
  75.  
  76. cout << endl << "String: " << stringMnoj << endl;
  77.  
  78. int* countersForMnoj = new int[strlen(stringMnoj)];
  79. for (int i = 0; i < strlen(stringMnoj); i++) {
  80. countersForMnoj[i] = 0;
  81.  
  82. }
  83.  
  84. char mostmetSub = mostMet(subMnoj, stringMnoj, countersForMnoj, strlen(stringMnoj), strlen(stringMnoj));
  85. changeString(stringMnoj, strlen(stringMnoj), mostmetSub);
  86.  
  87. delete[]countersForMnoj;
  88. countersForMnoj = NULL;
  89.  
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement