Advertisement
Alhiris

Untitled

Feb 21st, 2020
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. using namespace std;
  5. # define M_PI 3.14159265358979323846
  6. #define pb push_back
  7.  
  8. int transformer(string x){
  9. if(x=="patrat")
  10. return 0;
  11. else if(x=="dreptunghi")
  12. return 1;
  13. else if(x=="cerc")
  14. return 2;
  15. else if(x=="triunghi")
  16. return 3;
  17. return -1;
  18. }
  19.  
  20. class Prisme{
  21. public:
  22. string tipP;
  23. float h,l,L,r,c1,c2;
  24. const int gem=2,frisca=1;
  25. Prisme(string Type,float height,float lorr){
  26. h=height;
  27. if(Type=="patrat")
  28. l=lorr;
  29. else
  30. r=lorr;
  31. tipP=Type;
  32. }
  33. Prisme(string Type,float height,float l,float L){
  34. h=height;
  35. if(Type=="dreptunghi"){
  36. this->l=l;
  37. this->L=L;
  38. }else{
  39. this->c1=l;
  40. this->c2=L;
  41. }
  42. tipP=Type;
  43. }
  44.  
  45. float getGem(){
  46. switch(transformer(this->tipP)){
  47. case 0:
  48. return gem*(l*l*h);
  49. case 1:
  50. return gem*(l*L*h);
  51. case 2:
  52. return gem*(M_PI*r*r*h);
  53. case 3:
  54. return gem*(c1*c2*h/2);
  55. default:
  56. return -1;
  57. }
  58. }
  59. float getFrisca(){
  60. switch(transformer(this->tipP)){
  61. case 0:
  62. return (l*l*2+l*h*4)*frisca;
  63. case 1:
  64. return (l*L*2+L*h*2+l*h*2)*frisca;
  65. case 2:
  66. return (2*M_PI*(r*2))*((r*2)+h)*frisca;
  67. case 3:
  68. return ((c1+c2+sqrt(c1*c1+c2*c2))*h+(c1*c2))*frisca;
  69. default:
  70. return -1;
  71. }
  72. }
  73. };
  74.  
  75. int sumdiv(int x){
  76. long sum =1,i=0;
  77. for(i=2;i*i<x;++i)
  78. if(x%i==0)
  79. {
  80. sum+=i;
  81. sum+=(x/i);
  82. }
  83. sum+=((x%i==0)?i:0);
  84. return (sum==x);
  85. }
  86.  
  87. int main()
  88. {
  89. long a,b;
  90. cin>>a>>b;
  91. cout<<a+b;
  92. for(int i=a;i<=b;i++)
  93. if(sumdiv(i))
  94. cout<<i<<' ';
  95.  
  96. vector<Prisme> listaP;
  97. string X;
  98. while(cin>>X){
  99. if(X=="ADD"){
  100. float h,l,L,r;
  101. string Type;
  102. cin>>Type;
  103. if(transformer(Type)==0){
  104. cin>>h>>l;
  105. listaP.pb(new Prisme(Type,h,l));
  106. }
  107. else if(transformer(Type)==1){
  108. cin>>h>>l>>L;
  109. listaP.pb(new Prisme(Type,h,l,L));
  110. }
  111. else if(transformer(Type)==2){
  112. cin>>h>>l;
  113. listaP.pb(new Prisme(Type,h,l));
  114. }
  115. else if(transformer(Type)==3){
  116. cin>>h>>l>>L;
  117. listaP.pb(new Prisme(Type,h,l,L));
  118. }
  119. cout<<listaP.back().getGem()<<' '<<listaP.back().getFrisca()<<'\n';
  120. }
  121. else{
  122. int removal;
  123. cin>>removal;
  124. listaP.erase(listaP.begin()+removal-1);
  125. }
  126. }
  127. return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement