-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchina.cpp
208 lines (186 loc) · 4.23 KB
/
china.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll mod = 1000000007;
const ll inf = 1e18;
#define all(x) begin(x), end(x)
#define loop(i, n) for (int i = 0; i < n; i++)
#define print_array(arr) \
loop(z, sizeof(arr) / sizeof(arr[0])) cout << arr[z] << " "; \
cout << "\n"
#define print_vector(vvv) \
loop(z, vvv.size()) cout << vvv[z] << " "; \
cout << "\n"
#define print_vector_pair(vvv) \
loop(z, vvv.size()) cout << vvv[z].first << " " vvv[z].second << "\n"; \
cout << "\n"
#define fill_my(arr, q) fill(all(arr), q)
double buy = 0;
double sell = 0;
// void removeDupWord(string str)
// {
// string word = "";
// for (auto x : str)
// {
// if (x == ' ')
// {
// cout << word;
// word = "";
// }
// else
// {
// word = word + x;
// }
// }
// cout << word;
// }
string arr[10];
int no_of_buy=0;
int no_of_sell=0;
void removeDupWord(string str)
{
// Used to split string around spaces.
istringstream ss(str);
// Traverse through all words
int k = 0;
for (int i = 0; i < 10; i++)
{
// Read a word
string word;
ss >> word;
arr[k] = word;
k++;
// Print the read word
// cout << word<<" ";
// While there is more to read
}
}
void gaurav()
{
string s;
vector<string> v;
int kk = 0;
int k = 0;
while (getline(cin, s))
{
removeDupWord(s);
// cout << s;
for (int i = 0; i < 10; i++)
{
cout << arr[i] << " ";
}
cout << endl;
if (arr[2] == "G"){
kk++;
}
if (arr[2] == "G" && arr[5] == "buy")
{
buy = buy + (stod(arr[6]) * stod(arr[7]));
k++;
}
if (arr[2] == "G" && arr[5] == "sell")
{
sell = sell + (stod(arr[6]) * stod(arr[7]));
k++;
}
}
cout << endl
<< "\n\n\n\n"
<< "buy = " << buy << " sell = " << sell<<" "<<k<<" "<<kk<<" "<<"net = "<<(sell-buy);
// cout << endl;
// string row[10];
// int count = 0;
// for (int i = 0; i < 9; i++)
// {
// cin >> s;
// row[count] = s;
// }
// for (int i = 0; i < 10; i++)
// {
// cout << row[i];
// }
// cout << endl;
}
void solve()
{
string s;
while (cin >> s)
{
string package_name = "";
int startIndex = 0;
int endIndex = s.size() - 1;
for (int i = 0; i < s.size(); i++)
{
char c = s[i];
// cout<<c<<" "<<i<<endl;
if (c == '=' && s[i - 1] == 'd')
{
startIndex = i + 1;
// cout<<" start "<<startIndex;
}
if (c == '&')
{
endIndex = i - 1;
// cout<<" end "<<endIndex<<endl;
}
}
for (int i = startIndex; i <= endIndex; i++)
{
package_name += s[i];
}
cout << package_name << endl;
}
}
void delete_multiple()
{
string s;
vector<string> list;
while (cin >> s)
{
list.push_back(s);
}
for (int i = 0; i < list.size() - 1; i++)
{
for (int j = i + 1; j < list.size() - 2; j++)
{
if (list[i] == list[j])
{
list.erase(list.begin() + j);
}
}
}
for (int i = 0; i < list.size(); i++)
{
cout << list[i] << endl;
}
}
void sort()
{
string s;
vector<string> v;
while (cin >> s)
{
v.push_back(s);
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++)
{
cout << v[i] << endl;
}
}
int main()
{
clock_t time_req;
time_req = clock();
cin.sync_with_stdio(false);
cin.tie(0);
// solve();
// delete_multiple();
// sort();
gaurav();
// time_req = clock() - time_req;
// cout << "\nProcessor time " << (float)time_req / CLOCKS_PER_SEC<< " sec" << endl;
return 0;
}