1045怎么做错了???????????????

lixinyan 爱因斯坦 2024-02-20 20:52:57 0

#include

using namespace std;

int main() {

int a[1000000], n, zdz = 0, zdzwz = 0, zxz = 0, zxzwz = 0;

cin >> n;

for (int i = 1; i <= n; i++) {

    cin >> a[i];

    if (zdz < a[i]) {

        zdz = a[i];

        zdzwz = i;
    }
    if (zxz > a[i]) {

        zxz = a[i];

        zxzwz = i;
    }

}

cout << zxz << " " << zxzwz << " " << zdz << " " << zdzwz;

return 0;

}

{{ vote && vote.total.up }}

共 1 条回复

root 站长

初始化错了,最好用 a[1] 当最小值和最大值的初始值。