Advertisement
theo830

stacking boxes

Apr 27th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <stack>
  7. using namespace std;
  8. int isPrime(int n) {
  9. int i;
  10. if(n == 2) return 1;
  11. if(n%2 == 0) return 0;
  12. for(i = 3; i*i<=n; i+=2) {
  13. if(n%i == 0) return 0;
  14. }
  15. return 1;
  16. }
  17. int main() {
  18. int a;
  19. stack<int>s1;
  20. stack<int>s2;
  21. while(cin>>a){
  22. if(isPrime(a)){
  23. s1.push(a);
  24.  
  25. }
  26. else{
  27. s2.push(a);
  28. }
  29. }
  30. if(s1.top()== 2){
  31. while(!s2.empty()){
  32. cout<<s2.top()<<endl;
  33. s2.pop();
  34. }
  35. while(!s1.empty()){
  36. cout<<s1.top()<<endl;
  37. s1.pop();
  38. }
  39. }
  40. else if(s2.top()==4){
  41. while(!s1.empty()){
  42. cout<<s1.top()<<endl;
  43. s1.pop();
  44. }
  45. while(!s2.empty()){
  46. cout<<s2.top()<<endl;
  47. s2.pop();
  48. }
  49. }
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement