Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cassert>
- #include <vector>
- #include <string>
- using namespace std;
- vector<vector<char>> read_field(string filename) {
- auto file = fopen(filename.c_str(), "rt");
- assert(file != 0);
- int nRows, nCols;
- fscanf(file, "%d %d\n", &nRows, &nCols);
- vector<vector<char>> field(nRows, vector<char>(nCols));
- printf("nRows = %d, nCols = %d\n", nRows, nCols);
- for (int r = 0; r < nRows; ++r) {
- char buf[101]; fscanf(file, "%[^\n]s", buf); fscanf(file, "\n");
- for (int c = 0; c < nCols; ++c) {
- field[r][c] = buf[c];
- }
- // printf("%s\n", field.back().c_str());
- }
- fclose(file);
- return field;
- }
- int main(int argc, char* argv[]) {
- assert(argc == 3);
- auto f1 = read_field(argv[1]);
- auto f2 = read_field(argv[2]);
- int nRows = (int)f1.size();
- int nCols = (int)f1.front().size();
- printf("nRows = %d, nCols = %d\n", nRows, nCols);
- vector<vector<bool>> diff(nRows, vector<bool>(nCols));
- for (int r = 0; r < nRows; ++r) {
- for (int c = 0; c < nCols; ++c) {
- diff[r][c] = (f1[r][c] != f2[r][c]);
- printf("%c", f1[r][c]);
- }
- printf(" ");
- for (int c = 0; c < nCols; ++c) {
- printf("%c", f2[r][c]);
- }
- printf("\n");
- }
- for (int r = 0; r < nRows; ++r) {
- for (int c = 0; c < nCols; ++c) {
- printf(diff[r][c] ? "1" : "0");
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement