|
|
back to boardFunny trouble... Will u please give me some examples... cant understand what is wrong. #include<iostream> using namespace std; void bsort(int a[], int size) { register int i, j; int x; for(i=0;i<size;i++) { for(j=size-1;j>i;j--) { if(a[j-1]>a[j]) { x=a[j-1]; a[j-1]=a[j]; a[j]=x; } } } } struct { int x,y; } moves,border; int main(){ int n,x,i; cin >> n >> x; int* data = new int[n]; for(i=0;i<n;i++){ cin >> data[i]; } bsort(data,n); border.x = data[0]; border.y = data[n-1]; for(int i=1;i<n;i++){ if(data[i]>=x){ border.x = data[i-1]; break; } } for(int i=n-1;i>=0;i--){ if(data[i]<=x){ border.y = data[i+1]; break; } } if( (x<0 && border.x>x) || (x>0 && border.y<x) ){ cout << "Impossible"; return 0; } if(x<0){ moves.x = (-1)*x; moves.y = moves.x + border.y*2; } else if(x>0){ moves.y = x; moves.x = moves.y + (-1)*border.x*2; } cout << moves.y << " " << moves.x; return 0; } |
|
|