-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortedverification.cxx
52 lines (49 loc) · 1.54 KB
/
sortedverification.cxx
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
#include <iostream>
#include <fstream>
#include "json.hpp"
using json = nlohmann::json;
int main(int argc, char**argv)
{
if(argc !=2){
std::cout<<"Usage: "<<argv[0]<<" file.json"<<std::endl;
return -1;
}
json input;
std::ifstream ifs(argv[1]);
ifs >> input;
int arraySize=0, numSamples=0;
std::string sample="Sample";
numSamples=input["metadata"]["numSamples"];
arraySize=input["metadata"]["arraySize"];
json data=json::object();
int i=0,j=0,k=0,inversions=0;
for(i=1;i<=numSamples;i++){
std::string array_name=sample + std::to_string(i);
int count=0;
json CI=json::object();
for(j=0,k=j+1;j<arraySize-1 && k<arraySize;j++,k++){
if(input[array_name][j]>input[array_name][k]){
count++;
json array=json::array();
array.push_back(input[array_name][j]);
array.push_back(input[array_name][k]);
CI.push_back({std::to_string(count),array});
}
}
if(count>0){
inversions++;
json sample_info=json::object();
sample_info.push_back({"ConsecutiveInversions",CI});
sample_info.push_back({sample,input[array_name]});
data.push_back({array_name,sample_info});
}
}
json metadata=json::object();
metadata.push_back({"arraySize",arraySize});
metadata.push_back({"file","SampleExample.json"});
metadata.push_back({"numSamples",numSamples});
metadata.push_back({"samplesWithInversions",inversions});
data.push_back({"metadata",metadata});
std::cout<<data.dump(2)<<std::endl;
return 0;
}