-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
82 lines (63 loc) · 1.27 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
using namespace std;
void
minimumBribes(vector<int> q)
{
int count = 0;
for (int i=0; i<q.size(); i++)
{
if (q[i]-(i+1) > 2)
{
cout << "Too chaotic" << "\n";
return;
}
for (int j=max(0,q[i]-2); j < i; j++)
if (q[j] > q[i])
count++;
}
cout << count << "\n";
}
int
main(int argc, char **argv)
{
if (argc==1)
return 0;
ifstream filein (argv[1]);
string line;
string delimiter = " ";
int t;
int n;
if (filein.is_open())
{
size_t pos = 0;
string token;
getline ( filein, line );
string s = line;
t=stoi(s);
for (int i=0; i < t; i++)
{
getline ( filein, line );
string s = line;
n=stoi(s);
vector<int> arr(n);
getline ( filein, line );
s = line;
int j=0;
while ((pos = s.find(delimiter)) != string::npos)
{
token = s.substr(0, pos);
s.erase(0, pos+delimiter.length());
arr[j]=stoi(token);
j++;
}
minimumBribes(arr);
}
filein.close();
}
else
{
cout << "Unable to open file";
return 0;
}
return 0;
}