Advertisement
jelyslime

zadacha:Nai chesto sreshtana bukva v string

Jan 27th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void 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.     cout << "Nai sreshtanata bukva ot vuvedenoto mnojestvo e '" << sub[poz] << "' i tq se sreshta: " << counters[poz] << " puti." << endl;
  34.  
  35. }
  36.  
  37.  
  38.  
  39. int main()
  40. {
  41.         //zadacha stringove
  42.         // v sluchiq proverka na nai chesto sreshtan indeks ot mnojestvoto
  43.    
  44.  
  45.     char subMnoj[] = { 'e','t','i','s' };
  46.     char stringMnoj[] = { "This is a test string!" };
  47.    
  48.     cout << "Mnojestvo: " << endl;
  49.     for (int i = 0; i < strlen(stringMnoj); i++) {
  50.        
  51.         cout << subMnoj[i];
  52.        
  53.     }
  54.  
  55.     cout << endl << "String: " << stringMnoj << endl;
  56.  
  57.     int* countersForMnoj = new int[strlen(stringMnoj)]; //Razmera na cauntarite = na razmera na mnojestvoto
  58.     for (int i = 0; i < strlen(stringMnoj); i++){
  59.         countersForMnoj[i] = 0;
  60.  
  61.     }
  62.  
  63.     mostMet(subMnoj, stringMnoj, countersForMnoj, strlen(stringMnoj), strlen(stringMnoj));
  64.  
  65.  
  66.     delete[]countersForMnoj;
  67.     countersForMnoj = NULL;
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement