The text of the problem is given below. The task from the steppe, I will leave the link to the task below, since I need a text file to check the correctness of the solution, but its size is larger than the limit, so I can not attach it.

Problem.

On the example given to the task, everything works. But when I download the data file and check on it, then as it turned out the number of lines of "pairs" is greater than indicated in the first parameter of the first line. In my code, it turns out that after M * 2 there are addresses that are separately read into the array, but it turns out that it continues to read these "pairs" and everything does not work as it should. Even as I understand ATOI () converts to INT, and I have uint64_t, and it seems to me that the values ​​are "cropped" (if this is of course so), which also affects the task.

If you send the solution code through the MAP container, then please explain the code in more detail, because I still do not fully understand how to do it through MAP.

The input format is as follows:

in the first line, you are given 3 numbers m, q, r≥0, where q is the number of queries you need to answer, r is the physical address of the root page table of the next m lines, there are pairs of paddr and value is a description of physical memory, each pair means that a 64-bit value is stored at the physical address paddr, while it is guaranteed that all paddr are different, aligned to the 8-byte boundary and placed into 64 bits in the last q lines are integers - logical addresses that you need to convert to physical, for each of these numbers you need to bring to separate th row or the physical address or the word "fault", if you convert a logical address into a physical impossible. Assume that the page table has the format of 64-bit x86 mode (4 levels, each page is 4 KB, each record is 8 bytes, the record format was shown in lectures), but you can ignore all fields except the presence bit (in the picture, bit P is zero bit) and the actual physical address.

For all physical addresses that are not specified in the input data (among m paddr value pairs), assume that zeros are stored at these addresses. all physical addresses that are stored in the page table entries must be aligned at least with the border of 4096 bytes (4Kb), i.e. the lower 12 bits of the physical addresses are always 0, respectively, there is no point in storing the lower bits in the page table entry they are not stored - their place is occupied by special flags. Example: Sample Input: 4 4 0 0 4097 4096 8193 8192 12289 12288 16385 0 4096 42 131313

Sample Output: 16384 fault 16426 fault

An example of my code (yes, yes, it is terrible, do not throw slippers: (). Link to stepik at the very bottom.

#include <iostream> #include <fstream> #include <string> #include <bitset> using namespace std; bitset<64> PLM4(bitset<64>); bitset<64> NullBIT(bitset<64>); bitset<64> Smesch(bitset<64>); bool WordCount(string); int main() { char buff[1000]; //char* str = new char[100]; string str; uint64_t mas[3]; /* ofstream fout("Las_Vegas.txt"); fout << "4 4 0\n0 4097\n4096 8193\n8192 12289\n12288 16385\n0\n4096\n42\n131313"; fout.close(); */ ifstream file_out(""путь"\\dataset_44327_15.txt"); //ifstream file_out("Las_Vegas.txt"); for (int i = 0; i < 3; i++) { file_out >> buff; mas[i] = atoi(buff); } uint64_t *mass = new uint64_t[(mas[0] * 2)]; uint64_t *mas3 = new uint64_t[mas[1]]; getline(file_out, str); cout << str; for (uint64_t i = 0; i < ((mas[0] * 2) + mas[1]); i++) { if (i < (mas[0] * 2)) { file_out >> buff; mass[i] = atoi(buff); } //file_out.getline(str, '\n'); getline(file_out, str); //fgets(str, 100, file_out); if (i >= (mas[0] * 2)) { if (!WordCount(str)) { file_out >> buff; mas3[i - (mas[0] * 2)] = atoi(buff); } } } file_out.close(); bitset<64> CR3(mas[2]); bitset<64> offset; uint64_t a; for (int i = 0; i < mas[1]; i++) { bitset<64> prover(mas3[i]); bool breakF = false; //offset = Smesch(prover <<= 36); for (uint64_t j = 0; j < (mas[0] * 2); j = j + 2) { if (((CR3 | offset = PLM4(prover)).to_ulong() == mass[j]) || breakF) { for (int u = 1; u <= 4; j += 2, u++) { bitset<64> pr(mass[j + 1]); a = (pr = NullBIT(pr)).to_ulong(); a = ((pr = NullBIT(pr)) | (offset = Smesch(prover <<= (9 * (u - 1))))).to_ulong(); if (u == 4) { bitset<64> prover(mas3[i]); a = (offset = Smesch(prover <<= 38)).to_ulong(); cout << (pr.to_ulong() + a); } else if (!(a == mass[j + 2])) { cout << endl << "!!!" << "fault" << "!!!" << endl; j = j - 2 * (u - 1); breakF = true; break; }//if SECOND } if (!breakF) { j = j - 6; breakF = true; } break; } else { cout << endl << "!!!" << "fault" << "!!!" << endl; } } } system("PAUSE"); return 0; } bitset<64> PLM4(bitset<64> bit) { bit <<= 15; bit >>= 53; return bit; } bitset<64> Smesch(bitset<64> bit) { bit <<= 15; bit >>= 53; return bit; } bitset<64> NullBIT(bitset<64> bit) { bit >>= 12; bit <<= 12; return bit; } bool WordCount(string str) { int space = 1; for (int i = 1; i <= str.length(); i++) { if (str[i] == ' ') { space++; } } if ((space + 1) > 1) { return true; } else return false; 

}


 #include <iostream> #include <fstream> #include <string> #include <bitset> using namespace std; bitset<64> PLM4(bitset<64>); bitset<64> NullBIT(bitset<64>); bitset<64> Smesch(bitset<64>); bool WordCount(char []); int main() { char buff[1000]; //char* buff = new char[1000]; char* str = new char[100]; uint64_t mas[3]; /* ofstream fout("Las_Vegas.txt"); fout << "4 4 0\n0 4097\n4096 8193\n8192 12289\n12288 16385\n0\n4096\n42\n131313"; fout.close(); */ ifstream file_out("C:\\Users\\Nikita\\Desktop\\dataset_44327_15.txt"); //ifstream file_out("Las_Vegas.txt"); for (int i = 0; i < 3; i++) { file_out >> buff; mas[i] = atoi(buff); } uint64_t *mass = new uint64_t[(mas[0] * 2)]; uint64_t *mas3 = new uint64_t[mas[1]]; for (uint64_t i = 0; i < ((mas[0] * 2) + mas[1]); i++) { if (i < (mas[0] * 2)) { file_out >> buff; mass[i] = atoi(buff); } //file_out.getline(str, 100, '\n'); //fgets(str, 100, file_out); if (i >= (mas[0] * 2)){ file_out >> buff; mas3[i - (mas[0] * 2)] = atoi(buff); } } file_out.close(); bitset<64> CR3(mas[2]); bitset<64> offset; uint64_t a; for (int i = 0; i < mas[1]; i++) { bitset<64> prover(mas3[i]); bool breakF = false; //offset = Smesch(prover <<= 36); for (uint64_t j = 0; j < (mas[0] * 2); j = j + 2) { if (((CR3 | offset = PLM4(prover)).to_ulong() == mass[j]) || breakF) { for (int u = 1; u <= 4; j += 2, u++) { bitset<64> pr(mass[j + 1]); a = (pr = NullBIT(pr)).to_ulong(); a = ((pr = NullBIT(pr)) | (offset = Smesch(prover <<= (9 * (u - 1))))).to_ulong(); if (u == 4) { bitset<64> prover(mas3[i]); a = (offset = Smesch(prover <<= 38)).to_ulong(); cout << (pr.to_ulong() + a); } else if (!(a == mass[j + 2])) { cout << endl << "!!!" << "fault" << "!!!" << endl; j = j - 2 * (u - 1); breakF = true; break; }//if SECOND } if (!breakF) { j = j - 6; breakF = true; } break; } else { cout << endl << "!!!" << "fault" << "!!!" << endl; } } } //system("PAUSE"); return 0; } bitset<64> PLM4(bitset<64> bit) { bit <<= 15; bit >>= 53; return bit; } bitset<64> Smesch(bitset<64> bit) { bit <<= 15; bit >>= 53; return bit; } bitset<64> NullBIT(bitset<64> bit) { bit >>= 12; bit <<= 12; return bit; } /* bool WordCount(char str[]) { int space = 0; bool DVA = false; for (int i = 1; i <= strlen(str); i++) { if (str[i] == ' ') { space++; } } if ((space + 1) >1) { DVA = true; } return DVA; } */ 

Link to the task: https://stepik.org/lesson/44327/step/15?unit=22137

  • Для всех физических адресов, не указанных во входных данных (среди m пар paddr value), считайте, что по этим адресам хранятся нули. Maybe because of this, the number of pairs is greater than indicated in the first parameter of the first line? - vegorov
  • I passed this task, everything is fine there - in the example, first, m,q,r written, then in m lines of the paddr value pair, then in q lines there are requests to calculate the physical address by the logical address. - vegorov

0