Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <stack>
- using namespace std;
- int isPrime(int n) {
- int i;
- if(n == 2) return 1;
- if(n%2 == 0) return 0;
- for(i = 3; i*i<=n; i+=2) {
- if(n%i == 0) return 0;
- }
- return 1;
- }
- int main() {
- int a;
- stack<int>s1;
- stack<int>s2;
- while(cin>>a){
- if(isPrime(a)){
- s1.push(a);
- }
- else{
- s2.push(a);
- }
- }
- if(s1.top()== 2){
- while(!s2.empty()){
- cout<<s2.top()<<endl;
- s2.pop();
- }
- while(!s1.empty()){
- cout<<s1.top()<<endl;
- s1.pop();
- }
- }
- else if(s2.top()==4){
- while(!s1.empty()){
- cout<<s1.top()<<endl;
- s1.pop();
- }
- while(!s2.empty()){
- cout<<s2.top()<<endl;
- s2.pop();
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment