- 论坛徽章:
- 0
|
int a[10] = {5,1,7,3,4,18,15,24,20,10};
int min,max,big,small,result,tempResult1,tempResult2;
small = min = min(a[0],a[1]);
big = max = max(a[0],a[1]);
result = tempResult1 = tempResult2 = big - small;
cout << "result:" << result << " big:" << big << " small:" << small << endl;
cout << " tempResult1:" << tempResult1 << " tempResult2:" << tempResult2
<< " max:" << max << " min:" << min << endl;
cout << "初始化完毕" << endl;
for (int i=2;i<10;i++) {
if (a < big && a > small) {
tempResult1 = big - a;
tempResult2 = a - small;
if (tempResult1 > tempResult2) {
small = a;
result = tempResult1;
} else {
big = a;
result = tempResult2;
}
} else if (a > max) {
tempResult1 = a - max;
if (tempResult1 > result) {
big = a;
small = max;
result = tempResult1;
//cout << "changing2" << endl;
}
} else if (a < small) {
tempResult2 = small - a;
if (tempResult2 > result) {
big = small;
small = a;
result = tempResult2;
}
}
min = min(min, a);
max = max(max, a);
}
cout << "result:" << result << " big:" << big << " small:" << small << endl;
cout << " tempResult1:" << tempResult1 << " tempResult2:" << tempResult2
<< " max:" << max << " min:" << min << endl; |
|