Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- #include <iostream>
- #include "functions.h"
- using namespace std;
- int main() {
- const int size = 4;
- char set[size] = { 'e', 't', 'i', 's' };
- char * string = new char[100];
- int counter = 0;
- cout << "Enter your string: " << endl;
- cin.getline(string, 100);
- while (string[counter] != '\0')
- {
- counter++;
- }
- maxOccurancesInString(set, string, size, counter);
- return 0;
- }
- //functions.cpp
- #include <iostream>
- #include "functions.h"
- int maxOccurancesInString(char * set, char *string, unsigned setSize, unsigned stringSize)
- {
- int occurs = 0;
- int * occurances = new int[setSize];
- int counter = 0;
- for (size_t i = 0; i < setSize; i++)
- {
- occurs = 0;
- for (size_t k = 0; k < stringSize; k++)
- {
- if (set[i] == string[k])
- {
- occurs++;
- }
- if (k == stringSize - 1)
- {
- occurances[counter] = occurs;
- counter++;
- }
- }
- }
- int max = occurances[0];
- int positionMax = 0;
- for (int m = 0; m < counter; m++)
- {
- if (occurances[m] > max)
- {
- max = occurances[m];
- positionMax = m;
- }
- }
- std::cout << set[positionMax] << " - " << max << "\n";
- return 0;
- }
- //functions.h
- #ifndef _H_FUNCTIONS_H_
- #define _H_FUNCTIONS_H_
- int maxOccurancesInString(char *, char *, unsigned, unsigned);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement