|
|
back to boardWA #4 This is my code: #include <iostream> #include <cmath> using namespace std; int main() { int a[101], n, x, dis1 = 0, dis2 = 0, lb, rb; bool flag = false, flag2 = false;
cin >> n >> x;
if ((x == 0)) flag2 = true; else { if ( n == 0 ) flag = true; }
for ( int i = 0; i < n; i++ ) { cin >> a[i]; if ( (x > 0) && (a[i] < x) && (a[i] > 0) ) flag = true; if ( (x < 0) && (a[i] > x) && (a[i] < 0) ) flag = true; }
if (flag) cout << "Impossible" << endl; else { lb = a[0]; rb = a[0]; for ( int i = 1; i < n; i++ ) { if ( (a[i] > 0) && (a[i] > rb) && (a[i] > x) ) rb = a[i];
if ( (a[i] < 0) && (abs(a[i]) < abs(lb)) && (a[i] < x) ) lb = a[i]; }
if ( x > 0 ) { dis1 = x; dis2 = (int) abs(2*lb) + x; } else { dis1 = 2*rb + (int) abs(x); dis2 = (int) abs(x); }
if (flag2) cout << "0 0" << endl; else cout << dis1 << " " << dis2 << endl; }
system("PAUSE"); return 0; } --------------------------- I can't understand WHY WA#4 Please, help!!! Re: WA #4 It's too hard code. The real solution is much easier/ |
|
|