Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- int main () {
- ifstream f;
- f.open ("message_revised.txt");
- char b[9] = "";
- vector<vector<int>> combo;
- int count = 0;
- while(f.read(b, sizeof(b) - 1)){
- int found = 0;
- //printf("%s\n", b);
- for(int j = 0; j < combo.size(); j++){
- //printf("checking for equality %d == %d\n", atoi(b), combo[j][0]);
- if (atoi(b) == combo[j][0]) {
- combo[j][1]++;
- found = 1;
- }
- }
- if(found == 0){
- //printf("no match was found\n");
- combo.push_back(vector<int> ());
- combo[count].push_back(atoi(b));
- combo[count++].push_back(1);
- }
- f.seekg(2, f.cur);
- }
- vector<int> max;
- vector<int> pos;
- for (int k = 0; k < combo.size(); k++) {
- max.push_back(-5000000);
- pos.push_back(0);
- for(int i = 0; i < combo.size(); i++){
- //printf("%d\n", combo[i][0]);
- if(combo[i][1] > max[k]){
- max[k] = combo[i][1];
- pos[k] = i;
- }
- }
- printf("%d occured %d times\n", combo[pos[k]][0], max[k]);
- combo[pos[k]][1] = -1;
- }
- f.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement