-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathverify.cpp
73 lines (60 loc) · 1.89 KB
/
verify.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<vector<ll>> get_transactions(string file1){
vector<vector<ll>> transactions;
ifstream file(file1,ios::in);
if (file.good())
{
string str;
while(getline(file, str))
{
vector<ll> transaction;
istringstream ss(str);
ll item;
while(ss >> item)
{
transaction.push_back(item);
}
transactions.push_back(transaction);
}
}
return transactions;
}
void find_error(string file1, string file2){
auto transactions1 = get_transactions(file1);
auto transactions2 = get_transactions(file2);
if(transactions1.size() != transactions2.size()){
cout<<"No. of transactions doesnt match"<<"\n";
return;
}
ll num = transactions1.size();
for(ll i = 0;i<num;i++){
auto trans1 = transactions1[i];
auto trans2 = transactions2[i];
set<ll> tr1(trans1.begin(),trans1.end());
set<ll> tr2(trans2.begin(),trans2.end());
vector<ll> transaction1(tr1.begin(),tr1.end());
vector<ll> transaction2(tr2.begin(),tr2.end());
if(tr1.size() != tr2.size()){
cout<<"Size of " << i+1 << " transaction doesnt match"<<"\n";
return;
}
// sort(transaction1.begin(),transaction1.end());
// sort(transaction2.begin(),transaction2.end());
ll tr_size = transaction1.size();
for(ll j = 0;j<tr_size;j++){
if(transaction1[j] != transaction2[j]){
cout<<(j+1)<<"Item of "<<(i+1)<<" transaction doesnt match"<<"\n";
return;
}
}
}
cout<<"No error!"<<"\n";
}
int main(int argc, const char *argv[]){
string file1 = argv[1];
string file2 = argv[2];
find_error(file1,file2);
return 0;
}