-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathoutput_checker.cpp
More file actions
59 lines (55 loc) · 1.24 KB
/
output_checker.cpp
File metadata and controls
59 lines (55 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ifstream output1;
ifstream output2;
output1.open("out.txt", ios::in);
output2.open("res.txt", ios::in);
if (!output1) {
cout<<"Can't open output file 1\n";
return 0;
}
if (!output2) {
cout<<"Can't open output file 2\n";
return 0;
}
int lines = 1;
string str1, str2;
while (getline(output1, str1)) {
getline(output2, str2);
int a = str1.length();
int b = str2.length();
int lim = min(a, b);
int pos = 0;
bool c = false;
for(int i=0; i<lim; ++i) {
if (str1[i] != str2[i]) {
c = true;
break;
}
pos += 1;
}
if (c || a!=b) {
cout << "Output differs at line number : "<< lines << "\n";
cout << "The characters differ at position : " << (pos + 1) << "\n";
if (a < b) {
cout << "Output in file out.txt has shorter length\n";
}
else if (b < a) {
cout << "Output in file res.txt has shorter length\n";
}
return 0;
}
lines += 1;
}
cout << "Scanned a total of " << (lines - 1) << " lines from both files\n";
cout << "Both output files are same\n";
output1.close();
output2.close();
return 0;
}