#include using namespace std;

int main() { int n; cin >> n;

int heights[n];
for (int i = 0; i < n; i++) {
    cin >> heights[i];
}

bool canJump = true;
int currentHeight = heights[0];
for (int i = 1; i < n; i++) {
    if (heights[i] > currentHeight) {
        canJump = false;
        break;
    }
    currentHeight = heights[i];
}

if (canJump) {
    cout << "yes" << endl;
} else {
    cout << "no" << endl;
}

return 0;
c++只用iostream库使用布尔类型有n棵树排成一行高度为a1到an其中第1棵树上有一只小猫正准备跳到第2棵树上然后跳到第3棵树上以此类推……但是小猫只能跳到高度比当前树低的树上那么它能否跳到第n棵树上呢?例如5棵树高度分别为5、4、3、2、2则前4棵树都能跳到但是不能从第4棵跳到第5棵。所以答案是no。输入 第一行一个数nn100。第二行n个数依次表示树木高度。输出 能跳到第n棵树上的话输出

原文地址: https://www.cveoy.top/t/topic/ilI9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录