Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- char 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;
- }
- }
- for (int i = 0; i < sizeOfSub; i++)
- {
- if (sub[i] == sub[poz])
- {
- sub[i] == '!';
- }
- }
- return sub[poz];
- }
- void changeString(char* stringToChange, int stringSize, char mostMetChar)
- {
- for (int i = 0; i < stringSize; i++)
- {
- if (stringToChange[i] == mostMetChar) {
- stringToChange[i] = '!';
- }
- }
- cout << stringToChange;
- }
- int main()
- {
- char subMnoj[] = { 't','m','o','e','\0' };
- char stringMnoj[] = { "This is a test string!" };
- cout << "Mnojestvo: " << endl;
- for (int i = 0; i < strlen(stringMnoj); i++) {
- if (subMnoj[i] == '\0')
- {
- break;
- }
- cout << subMnoj[i];
- }
- cout << endl << "String: " << stringMnoj << endl;
- int* countersForMnoj = new int[strlen(stringMnoj)];
- for (int i = 0; i < strlen(stringMnoj); i++) {
- countersForMnoj[i] = 0;
- }
- char mostmetSub = mostMet(subMnoj, stringMnoj, countersForMnoj, strlen(stringMnoj), strlen(stringMnoj));
- changeString(stringMnoj, strlen(stringMnoj), mostmetSub);
- delete[]countersForMnoj;
- countersForMnoj = NULL;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement