|
|
вернуться в форумWA #13 Послано Hi4ko 7 дек 2011 19:22 why? #include <iostream> #include <cmath> using namespace std; #define SWAP(A, B) { int t = A; A = B; B = t; } void bubblesort(int *a, int n) { int i, j; for (i = n - 1; i > 0; i--) { for (j = 0; j < i; j++) { if (a[j] > a[j + 1]) SWAP( a[j], a[j + 1] ); } } } int main() { int n,x,ar[100]; cin>>n>>x; for(int i=0;i<n;i++) cin>>ar[i]; bubblesort(ar,n); int j=0; while(ar[j]<0 && j<n-1) ++j; if(ar[j-1]<x && ar[j]>x && n!=1 ) { if(x<0) cout<<2*ar[j]-x<<" "<<0-x; else cout<<x<<" "<<abs(2*ar[j-1])+x; } else if(n==1) { if(ar[0] > x) cout<<2*abs(ar[0])-x<<" "<<-x; else cout<<x<<" "<<2*abs(ar[0])+x; } else cout<<"Impossible"; } Re: WA #13 Послано NUUZ_1 14 янв 2012 20:54 I am also get WA#13.I don't understand why. Please help me. My code is #include"iostream" using namespace std; int main() { int x[100]; int n, x0; cin>>n; cin>>x0; if(n==0){cout<<"Impossible"; return 0;} for(int i=0;i<n;i++) cin>>x[i]; if(n==1) { n=2; x[1]=x0; } for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) if(x[j]<x[i]) { int t=x[i]; x[i]=x[j]; x[j]=t; } int i=0; for(;i<n-1;i++) { if(x0>=x[i]&&x0<=x[i+1]) { if(x[i]<=0&&x[i+1]>=0) { if(x0>0) { cout<<x0<<' '<<x0+abs(2*x[i]); return 0; } else { cout<<2*x[i+1]+abs(x0)<<' '<<abs(x0); return 0; } } } } cout<<"Impossible"; return 0; } |
|
|