Repository navigation
Expand file tree
/
Copy path0035.cpp
More file actions
80 lines (68 loc) · 1.65 KB
/
Copy path0035.cpp
File metadata and controls
80 lines (68 loc) · 1.65 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <set>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <limits.h>
using namespace std;
int searchInsert(vector<int>& nums, int target) {
int n=nums.size();
if (n==0) return -1;
int lo=0, hi=n-1;
while (lo<=hi) {
int mid = (lo+hi)/2;
if (nums[mid]<target)
lo = mid + 1;
else
hi = mid-1;
}
return lo;
}
string filename = "0035.txt";
const auto& myFunc = searchInsert;
int main() {
string vin, nrin;
vector<vector<int>> vv;
vector<int> vn;
vector<int> vr;
ifstream fp;
fp.open(filename);
int d;
while (getline(fp, vin, '\n')) {
stringstream sv(vin);
vector<int> vvi = {};
while (sv >> d) {
vvi.push_back(d);
}
vv.push_back(vvi);
getline(fp, nrin, '\n');
stringstream snr(nrin);
snr >> d;
vn.push_back(d);
snr >> d;
vr.push_back(d);
}
fp.close();
printf("%s\t%s\t%s\t%s\n", "T","L", "√", "?");
printf("--- --- --- --- \n");
int correct_cnt=0;
for (int i=0; i<vr.size(); ++i) {
int res = myFunc(vv[i],vn[i]);
bool is_correct = res==vr[i];
printf("%s\t%d\t%d\t%d\n", is_correct?" ":"x", 2*i+1, vr[i], res);
if (is_correct) ++correct_cnt;
}
printf("--- --- --- --- \n");
printf("%s\t%d/%d\n", correct_cnt==vr.size()?"√":"×",correct_cnt, vr.size());
return 0;
}