Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- float negative_temp=0;
- float negative_min=0;
- float lowpozitive_max=0;
- float lownegative_max1=0;
- float lownegative_max2=0;
- int negative_amount=0;
- int pozitive_amount=0;
- int zero_amount=0;
- int main()
- {
- float a[]={-1, -2, -4, -9, -0.3, 0.02, -0.1, 100};
- int N=sizeof(a)/4; //на float выделяется 4 байта
- if (N==1) {std::cout<<a[0]<<'\n'; return 0;}
- else if (N==0) return 0;
- else for (int i=0; i<N; i++)
- {
- if (abs(a[i])>1)
- {
- if (a[i]>0) {std::cout<<a[i]<<'\n'; pozitive_amount++;}
- else
- {
- negative_amount++;
- if (negative_min==0) {negative_min=a[i];}
- else
- {
- if (negative_min<a[i])
- {
- float temp=negative_min;
- negative_min=a[i];
- a[i]=temp;
- }
- if(negative_temp) {std::cout<<negative_temp<<'\n'<<a[i]<<'\n'; negative_temp=0;}
- else negative_temp=a[i];
- }
- }
- }
- else if (a[i]>0) {if (a[i]>lowpozitive_max) lowpozitive_max=a[i];}
- else if (a[i]<0)
- {
- if (a[i]<lownegative_max1) lownegative_max1=a[i];
- else if(a[i]<=lownegative_max2) lownegative_max2=a[i];
- }
- else if (a[i]==0) zero_amount++;
- }
- if (!negative_amount && !pozitive_amount)
- {
- if (!lowpozitive_max)
- if (!lownegative_max1) std::cout<<0<<'\n';
- else if (!lownegative_max2) std::cout<<lownegative_max1<<'\n';
- else std::cout<<lownegative_max1<<'\n'<<lownegative_max2<<'\n';
- else if (lownegative_max1*lownegative_max2<lowpozitive_max)
- std::cout<<lowpozitive_max<<'\n';
- else if (lownegative_max1*lownegative_max2>lowpozitive_max)
- std::cout<<lownegative_max1<<'\n'<<lownegative_max2<<'\n';
- }
- else if (abs(negative_amount%2))
- {
- if (negative_min*lownegative_max1>1) std::cout<<negative_min<<'\n'<<lownegative_max1<<'\n';
- else if (!lownegative_max1 && !pozitive_amount && (negative_amount==1))
- if (!lowpozitive_max) std::cout<<negative_min<<'\n';
- else std::cout<<lowpozitive_max<<'\n';
- }
- else if (negative_temp) std::cout<<negative_temp<<'\n'<<negative_min<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement