Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. float negative_temp=0;
  5. float negative_min=0;
  6. float lowpozitive_max=0;
  7. float lownegative_max1=0;
  8. float lownegative_max2=0;
  9. int negative_amount=0;
  10. int pozitive_amount=0;
  11. int zero_amount=0;
  12.  
  13. int main()
  14. {
  15.     float a[]={-1, -2, -4, -9, -0.3, 0.02, -0.1, 100};
  16.     int N=sizeof(a)/4; //на float выделяется 4 байта
  17.  
  18.     if (N==1) {std::cout<<a[0]<<'\n'; return 0;}
  19.     else if (N==0) return 0;
  20.     else for (int i=0; i<N; i++)
  21.     {
  22.         if (abs(a[i])>1)
  23.         {  
  24.             if (a[i]>0) {std::cout<<a[i]<<'\n'; pozitive_amount++;}
  25.             else
  26.             {
  27.                 negative_amount++;
  28.                 if (negative_min==0) {negative_min=a[i];}
  29.                 else
  30.                 {
  31.                     if (negative_min<a[i])
  32.                     {
  33.                         float temp=negative_min;
  34.                         negative_min=a[i];
  35.                         a[i]=temp;
  36.                     }
  37.                     if(negative_temp) {std::cout<<negative_temp<<'\n'<<a[i]<<'\n'; negative_temp=0;}
  38.                     else negative_temp=a[i];
  39.                 }
  40.             }
  41.         }
  42.         else if (a[i]>0) {if (a[i]>lowpozitive_max) lowpozitive_max=a[i];}
  43.         else if (a[i]<0)
  44.         {
  45.             if (a[i]<lownegative_max1) lownegative_max1=a[i];
  46.             else if(a[i]<=lownegative_max2) lownegative_max2=a[i];
  47.         }
  48.         else if (a[i]==0) zero_amount++;
  49.     }
  50.    
  51.     if (!negative_amount && !pozitive_amount)
  52.     {
  53.         if (!lowpozitive_max)
  54.             if (!lownegative_max1)  std::cout<<0<<'\n';
  55.             else if (!lownegative_max2) std::cout<<lownegative_max1<<'\n';
  56.             else std::cout<<lownegative_max1<<'\n'<<lownegative_max2<<'\n';
  57.         else if (lownegative_max1*lownegative_max2<lowpozitive_max)
  58.             std::cout<<lowpozitive_max<<'\n';
  59.         else if (lownegative_max1*lownegative_max2>lowpozitive_max)
  60.             std::cout<<lownegative_max1<<'\n'<<lownegative_max2<<'\n';
  61.     }
  62.     else if (abs(negative_amount%2))
  63.     {
  64.         if (negative_min*lownegative_max1>1) std::cout<<negative_min<<'\n'<<lownegative_max1<<'\n';
  65.         else if (!lownegative_max1 && !pozitive_amount && (negative_amount==1))
  66.             if (!lowpozitive_max) std::cout<<negative_min<<'\n';
  67.             else std::cout<<lowpozitive_max<<'\n';
  68.     }
  69.     else if (negative_temp) std::cout<<negative_temp<<'\n'<<negative_min<<'\n';
  70.  
  71.    
  72.  
  73.        
  74.  
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement