#3606. 模拟读程序

模拟读程序

题目描述

阅读程序,判断输出结果。

#include <iostream>
using namespace std;

int main() {
    int pos = 0;
    int a[5] = {1, 1, -1, 2, -2};

    for (int i = 0; i < 5; i++) {
        pos += a[i];
        if (pos < 0) {
            pos = 0;
        }
    }

    cout << pos;
    return 0;
}

{{ select(1) }}

  • A. 0
  • B. 1
  • C. 2
  • D. 3