Advertisement
Guest User

Untitled

a guest
Apr 28th, 2010
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int a[]={-1,1,2,0,-5,0,-7};
  7.     const int N=6;
  8.     int negative=0,nulls=-1,min=0,maxnegative=0;
  9.     for (int i=0;i<N;++i)
  10.     {
  11.         if (a[i]>0 && (a[i]<a[min]||a[min]<=0))
  12.            min=i;
  13.         else if (a[i]==0)
  14.         {
  15.             if (nulls==-1) nulls=i;
  16.             else {
  17.                 for (int i=0;i<N;++i)
  18.                   if (i!=nulls) cout<<a[i]<<" ";
  19.                 return 0;
  20.             }
  21.         }
  22.         else if (a[i]<0)
  23.         {
  24.             ++negative;
  25.             if (a[i]>a[maxnegative] || a[maxnegative]>=0) maxnegative=i;
  26.         }
  27.     }
  28.    
  29.     if (negative%2==0)
  30.     {
  31.         if (nulls!=-1)
  32.         {
  33.             for (int i=0;i<N;++i)
  34.             if (i!=nulls) cout<<a[i]<<" ";
  35.         }
  36.         else {
  37.            for (int i=0;i<N;++i)
  38.             if (i!=min) cout<<a[i]<<" ";
  39.         }
  40.     }
  41.     else if(negative%2)
  42.     {
  43.             for (int i=0;i<N;++i)
  44.             if (i!=maxnegative) cout<<a[i]<<" ";
  45.     }
  46.            
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement