int main() { int filesCount; cin >> filesCount; if (filesCount == 0) return 0; cin.ignore(); char** files = readFilesFromStdOut(filesCount); char* smallestFile = getSmallestFile(files, filesCount); HashSet* hs = initialize(smallestFile); for (int i = 0; i < filesCount; ++i) { char* currentFile = files[i]; // skip the smallest file if (!strcmp(currentFile, smallestFile)) continue; HashSet* intersection = new HashSet(hs->getCapacity()); ifstream is(currentFile); while (true) { uint_64 n; is.read((char*)&n, sizeof(uint_64)); if (is.eof()) break; if (hs->contains(n)) intersection->add(n); } is.close(); // If at some point the intersection is empty // we no longer have to check the other files if (intersection->isEmpty()) break; delete hs; // Swap the previous intersection with the new one hs = intersection; } // Write the output in binary file hs->serializeToFile("result.bin"); delete hs; for (int i = 0; i < filesCount; ++i) delete[] files[i]; delete[] files; delete[] smallestFile; system("pause"); return 0; };