-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStock Buy and Sell.cpp
50 lines (43 loc) · 951 Bytes
/
Stock Buy and Sell.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
//{ Driver Code Starts
// Initial template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution {
public:
int maximumProfit(vector<int> &prices) {
// code here
int sol=0;
int n = prices.size();
for(int i=1;i<n;i++)
{
if (prices[i] > prices[i - 1]) sol+=prices[i] - prices[i-1];
}
return sol;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
cin.ignore();
while (t--) {
vector<int> arr;
string input;
getline(cin, input);
stringstream ss(input);
int number;
while (ss >> number) {
arr.push_back(number);
}
int n = arr.size();
Solution ob;
int res = ob.maximumProfit(arr);
cout << res;
cout << "\n";
cout << "~"
<< "\n";
}
return 0;
}
// } Driver Code Ends