-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd41175
commit e7d0e73
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int height(stack<int> a, stack<int> b, stack<int> c) | ||
{ | ||
while(1){ | ||
if(a.empty() || b.empty() || c.empty()) | ||
return 0; | ||
|
||
int atop = a.top(), btop = b.top(), ctop = c.top(); | ||
//cout << atop << endl; | ||
if(atop == btop && btop == ctop) | ||
return atop; | ||
|
||
if(atop >= btop && atop >= ctop) | ||
a.pop(); | ||
else if(btop >= atop && btop >= ctop) | ||
b.pop(); | ||
else if(ctop >= atop && ctop >= btop) | ||
c.pop(); | ||
|
||
} | ||
} | ||
|
||
stack<int> input(int n) | ||
{ | ||
vector<int> v(n); | ||
for(int i = 0; i < n; i++) | ||
cin >> v[i]; | ||
|
||
stack<int> s; | ||
int sm = 0; | ||
for(int i = n - 1; i >= 0; i--){ | ||
sm += v[i]; | ||
s.push(sm); | ||
} | ||
|
||
return s; | ||
} | ||
|
||
int main(void) | ||
{ | ||
int a, b, c; | ||
cin >> a >> b >> c; | ||
|
||
stack<int> as = input(a), bs = input(b), cs = input(c); | ||
|
||
cout << height(as, bs, cs) << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main(void) | ||
{ | ||
int t; | ||
cin >> t; | ||
|
||
stack<string> s; | ||
string ss; | ||
for(int i = 0, n, k; i < t; i++){ | ||
cin >> n; | ||
string st; | ||
|
||
if(n == 1){ | ||
cin >> st; | ||
s.push(ss); | ||
ss += st; | ||
} | ||
else if(n == 2){ | ||
cin >> k; | ||
s.push(ss); | ||
ss.erase(ss.size() - k); | ||
} | ||
else if(n == 3){ | ||
cin >> k; | ||
cout << ss[k-1] << endl; | ||
} | ||
else if(n == 4){ | ||
ss = s.top(); | ||
s.pop(); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <bits/stdc++.h> | ||
#define MAX 11002 | ||
using namespace std; | ||
|
||
vector<int> prime; | ||
bool primecheck[MAX]; | ||
|
||
void primeFunction(void) | ||
{ | ||
int limit = sqrt(MAX); | ||
|
||
primecheck[0] = 1, primecheck[1] = 1; | ||
for(int i = 4; i <= MAX; i += 2) | ||
primecheck[i] = 1; | ||
|
||
prime.push_back(2); | ||
for(int i = 3; i <= MAX; i += 2){ | ||
if(!primecheck[i]){ | ||
prime.push_back(i); | ||
|
||
if(i <= limit){ | ||
for(int j = i * i; j <= MAX; j += i * 2) | ||
primecheck[j] = 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
int main(void) | ||
{ | ||
primeFunction(); | ||
//cout << v.size() << endl; | ||
int n, q; | ||
cin >> n >> q; | ||
|
||
stack<int> s; | ||
for(int i = 0, a; i < n; i++){ | ||
cin >> a; | ||
s.push(a); | ||
} | ||
|
||
int con = 0; | ||
stack<int>v[1201]; | ||
while(con < q){ | ||
int p = prime[con]; | ||
stack<int> temp; | ||
while(!s.empty()){ | ||
if(s.top() % p == 0) | ||
v[con].push(s.top()); | ||
else | ||
temp.push(s.top()); | ||
s.pop(); | ||
} | ||
s = temp; | ||
con++; | ||
} | ||
|
||
for(int i = 0; i < q; i++){ | ||
while(!v[i].empty()){ | ||
cout << v[i].top() << endl; | ||
v[i].pop(); | ||
} | ||
} | ||
|
||
while(!s.empty()){ | ||
cout << s.top() << endl; | ||
s.pop(); | ||
} | ||
|
||
return 0; | ||
} |