Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- void mostMet(char* sub, char* stringMnoj, int* counters, int sizeOfSub, int sizeOfString)
- {
- int poz = 0;
- int tempBiggest = 0;
- for (int j = 0; j < strlen(stringMnoj); j++) {
- for (int k = 0; k < strlen(sub); k++) {
- if (sub[k] == stringMnoj[j])
- {
- counters[k] = counters[k] + 1;
- continue;
- }
- }
- }
- for (int i = 0; i < sizeOfSub; i++)
- {
- if (counters[i] > tempBiggest)
- {
- tempBiggest = counters[i];
- poz = i;
- }
- }
- cout << "Nai sreshtanata bukva ot vuvedenoto mnojestvo e '" << sub[poz] << "' i tq se sreshta: " << counters[poz] << " puti." << endl;
- }
- int main()
- {
- //zadacha stringove
- // v sluchiq proverka na nai chesto sreshtan indeks ot mnojestvoto
- char subMnoj[] = { 'e','t','i','s' };
- char stringMnoj[] = { "This is a test string!" };
- cout << "Mnojestvo: " << endl;
- for (int i = 0; i < strlen(stringMnoj); i++) {
- cout << subMnoj[i];
- }
- cout << endl << "String: " << stringMnoj << endl;
- int* countersForMnoj = new int[strlen(stringMnoj)]; //Razmera na cauntarite = na razmera na mnojestvoto
- for (int i = 0; i < strlen(stringMnoj); i++){
- countersForMnoj[i] = 0;
- }
- mostMet(subMnoj, stringMnoj, countersForMnoj, strlen(stringMnoj), strlen(stringMnoj));
- delete[]countersForMnoj;
- countersForMnoj = NULL;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement