|
|
вернуться в форумWhy "Compilation error"? (C++) Послано Osanve 27 янв 2011 04:49 My OS: Linux Ubuntu 10.10 I use gcc 4.4.5 (don't have OS Windows) On my computer no errors and warnings Program source: #include <iostream> #define abs(x) ((x)<0 ? -(x) : (x)) using namespace std; int main() { short n; long sum = 0; long firstSum = 0; long secondSum = 0; cin >> n; long w[n]; for(int i=0; i<n; i++) { cin >> w[i]; sum+=w[i]; } sum>>=1; long temp = w[0]; int num = 0; for(int i=0; i<n; i++) { if(temp<w[i]) { temp = w[i]; num = i; } } firstSum+=temp; w[num] = 0; for(int i=1; i<n; i++) { num = 0; while(w[num]==0) { num++; } temp = w[num]; for(int j=0; j<n; j++) { if((temp>w[j])&&(w[j]!=0)) { temp = w[j]; num = j; } } w[num] = 0; if(firstSum+temp<sum) { firstSum+=temp; } else { secondSum+=temp; } } cout << abs(firstSum-secondSum) << endl; return 0; } |
|
|