#include #include #include #include #include #include #include using namespace std; int byteSize = 12; int i = 0; char zeroChar = '0'; bool bitIsFalse(string binString) { return (binString[i] == '0'); } bool bitIsTrue(string binString) { return (binString[i] == '1'); } int main (void) { string inputValues; string mostCommonList; string mostCommonWorking; string leastCommonList; string leastCommonWorking; string currentLine; string mostCommonFinal; string leastCommonFinal; int oxygenGenRatingDec = 0; int coScrubRatingDec = 0; int lifeSupport = 0; ifstream readFile ("data/input.txt", ios::in); //file Read while(getline(readFile, currentLine)) { byteSize = currentLine.length(); inputValues.append(currentLine); } int mostBitTrue[byteSize] = {}; int mostBitFalse[byteSize] = {}; int leastBitTrue[byteSize] = {}; int leastBitFalse[byteSize] = {}; int oxygenGenRatingBin[byteSize] = {}; int coScrubRatingBin[byteSize] = {}; mostCommonList = inputValues; mostCommonWorking = mostCommonList; leastCommonList = inputValues; leastCommonWorking = leastCommonList; //most Common filter //Iterate through all bits in line for(i=0;i mostBitFalse[i]) { //iterate through string for (int j=(mostCommonList.length() / byteSize);j>=0;j--) { //remove byte with indexed bit of 0 if (mostCommonList[j*byteSize + i] == '0') mostCommonWorking.erase(j*byteSize, byteSize); } } //If more 0s than 1s if (mostBitFalse[i] > mostBitTrue[i]) { //iterate through string for (int j=(mostCommonList.length() / byteSize);j>=0;j--) { // remove byte with indexed bit of 1 if (mostCommonList[j*byteSize + i] == '1') mostCommonWorking.erase(j*byteSize, byteSize); } } mostCommonList = mostCommonWorking; //testing block for (int j=0;j<(mostCommonList.length() / byteSize);j++) { cout << mostCommonList[j*byteSize] << mostCommonList[j*byteSize + 1] << mostCommonList[j*byteSize + 2] << mostCommonList[j*byteSize + 3] << mostCommonList[j*byteSize + 4] << endl; } cout << endl << "******************************" << endl; } cout << "Final Most Common: "; mostCommonFinal = mostCommonList; cout << mostCommonFinal << endl; //******************************************************************* //least Common filter //Iterate through all bits in line for(i=0;i leastBitFalse[i]) { //iterate through string for (int j=(leastCommonList.length() / byteSize);j>=0;j--) { //remove byte with indexed bit of 0 if (leastCommonList[j*byteSize + i] == '1') leastCommonWorking.erase(j*byteSize, byteSize); } } //If more 0s than 1s if (leastBitFalse[i] > leastBitTrue[i]) { //iterate through string for (int j=(leastCommonList.length() / byteSize);j>=0;j--) { // remove byte with indexed bit of 1 if (leastCommonList[j*byteSize + i] == '0') leastCommonWorking.erase(j*byteSize, byteSize); } } leastCommonList = leastCommonWorking; //testing block for (int j=0;j<(leastCommonList.length() / byteSize);j++) { cout << leastCommonList[j*byteSize] << leastCommonList[j*byteSize + 1] << leastCommonList[j*byteSize + 2] << leastCommonList[j*byteSize + 3] << leastCommonList[j*byteSize + 4] << endl; } cout << endl << "******************************" << endl; } cout << "Final least Common: "; leastCommonFinal = leastCommonList; cout << leastCommonFinal << endl; for(i=0;i