Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <cstring>
- using namespace std;
- int main () {
- ifstream f;
- f.open ("nospace2.txt");
- const int n = 41;
- char b[n] = "";
- struct data{
- char digits[n];
- int repeats;
- };
- vector<data> 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("comparing b = %s and digits = %s ", b, combo[j].digits);
- if (strcmp(b, combo[j].digits) == 0) {
- combo[j].repeats++;
- found = 1;
- //printf("They match!");
- }
- //printf("\n");
- }
- if(found == 0){
- combo.push_back(data());
- strcpy(combo[count].digits, b);
- combo[count++].repeats = 1;
- //printf("no match was found, setting combo[%d].repeats = %d and digits = %s\n", count - 1, combo[count - 1].repeats, combo[count - 1].digits); //ignore
- }
- f.seekg((-n+9), 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]); //ignore
- if(combo[i].repeats > max[k]){
- max[k] = combo[i].repeats;
- pos[k] = i;
- }
- }
- printf("%s occured %d times\n", combo[pos[k]].digits, max[k]);
- combo[pos[k]].repeats = -1;
- }
- f.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement