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");
- struct data{
- char *digits;
- int repeats;
- };
- for(int w = 9; w < 3201; w = w + 8){
- char *b;
- b = new char[w];
- b[(sizeof(b)/sizeof(*b))] = 0;
- vector<data> combo;
- int count = 0;
- while(f.read(b, w - 1)){
- int found = 0;
- //printf("%s ", 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());
- combo[count].digits = new char[w];
- 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((-w+9), f.cur);
- }
- f.clear();
- f.seekg(0);
- int numoftwos = 0;
- int pos = 0;
- for(int k = 0; k < combo.size(); k++){
- if(combo[k].repeats == 2){
- numoftwos++;
- pos = k;
- }
- }
- if(numoftwos == 1){
- printf("It worked with n = %d, value is %s\n", w, combo[pos].digits);
- //break;
- }else{
- printf("Failed for n = %d, numoftwos = %d\n", w, numoftwos);
- }
- delete [] b;
- combo.clear();
- vector<data>().swap(combo);
- }
- /*
- 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