Advertisement
dmkozyrev

compare.cpp

Apr 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cassert>
  3. #include <vector>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. vector<vector<char>> read_field(string filename) {
  9.     auto file = fopen(filename.c_str(), "rt");
  10.     assert(file != 0);
  11.     int nRows, nCols;
  12.     fscanf(file, "%d %d\n", &nRows, &nCols);
  13.     vector<vector<char>> field(nRows, vector<char>(nCols));
  14.     printf("nRows = %d, nCols = %d\n", nRows, nCols);
  15.     for (int r = 0; r < nRows; ++r) {
  16.         char buf[101]; fscanf(file, "%[^\n]s", buf); fscanf(file, "\n");
  17.         for (int c = 0; c < nCols; ++c) {
  18.             field[r][c] = buf[c];
  19.         }
  20. //        printf("%s\n", field.back().c_str());
  21.     }
  22.     fclose(file);
  23.     return field;
  24. }
  25.  
  26. int main(int argc, char* argv[]) {
  27.     assert(argc == 3);
  28.     auto f1 = read_field(argv[1]);
  29.     auto f2 = read_field(argv[2]);
  30.     int nRows = (int)f1.size();
  31.     int nCols = (int)f1.front().size();
  32.     printf("nRows = %d, nCols = %d\n", nRows, nCols);
  33.     vector<vector<bool>> diff(nRows, vector<bool>(nCols));
  34.     for (int r = 0; r < nRows; ++r) {
  35.         for (int c = 0; c < nCols; ++c) {
  36.             diff[r][c] = (f1[r][c] != f2[r][c]);
  37.             printf("%c", f1[r][c]);
  38.         }
  39.         printf("    ");
  40.         for (int c = 0; c < nCols; ++c) {
  41.             printf("%c", f2[r][c]);
  42.         }
  43.         printf("\n");
  44.     }
  45.  
  46.     for (int r = 0; r < nRows; ++r) {
  47.         for (int c = 0; c < nCols; ++c) {
  48.             printf(diff[r][c] ? "1" : "0");
  49.         }
  50.         printf("\n");
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement