-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequalStack.cpp
130 lines (121 loc) · 3.25 KB
/
equalStack.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
//https://www.hackerrank.com/challenges/equal-stacks
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
int summatIon(vector <int>data)
{
int sum=0,i=0;
while(i != data.size())
{
sum += data[i];
i++;
}
return sum;
}
int main(){
int n1;
int n2;
int n3;
cin >> n1 >> n2 >> n3;
vector<int> h1(n1);
for(int h1_i = 0;h1_i < n1;h1_i++){
cin >> h1[h1_i];
// cout << h1[h1_i] << endl;
}
vector<int> h2(n2);
for(int h2_i = 0;h2_i < n2;h2_i++){
cin >> h2[h2_i];
}
vector<int> h3(n3);
for(int h3_i = 0;h3_i < n3;h3_i++){
cin >> h3[h3_i];
}
while(!h1.empty() && !h2.empty() && !h3.empty())
{
int sum1 = summatIon(h1);
int sum2 = summatIon(h2); //this function is use to add the vector element and return the value in the sum1;
int sum3 = summatIon(h3);
//i think i sbstrack each time that element which i delete so its may be the complexity of that program is come.
if(sum1==0 || sum2==0 ||sum3==0)
{
cout << 0 << endl;
return 0;
}
if(sum1 == sum2 && sum1 == sum3 && sum2 == sum3)
{
//cout <<"is it u" << sum1 << " " << sum2 << " "<< sum3 << endl;
cout << sum1<<endl;
return 0;
}
if(sum1>sum2 && sum1 > sum3 )
{
if(sum2 > sum3)
{
h1.erase(h1.begin());
h2.erase(h2.begin());
}
else if(sum2 == sum3)
{
h1.erase(h1.begin());
}
else{
h1.erase(h1.begin());
h3.erase(h3.begin());
}
}
else if(sum2>sum1 && sum2>sum3)
{
if(sum1>sum3)
{
h2.erase(h2.begin());
h1.erase(h1.begin());
}
else if(sum1 == sum3)
{
h2.erase(h2.begin());
}
else{
h2.erase(h2.begin());
h3.erase(h3.begin());
}
}
else {
if(sum1>sum2)
{
h3.erase(h3.begin());
h1.erase(h1.begin());
}
else if(sum1 == sum2)
{
h3.erase(h3.begin());
}
else{
h3.erase(h3.begin());
h2.erase(h2.begin());
}
}
}
if(h1.empty() || h2.empty() || h3.empty())
cout << 0 <<endl;
return 0;
}