#include<iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    int count = 0; // 计数器,用于统计负数的个数
    for (int i = 0; i < n; i++) {
        int num;
        cin >> num;
        if (num < 0) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

问题描述: 输入 n 个整数,统计其中负数的个数。

提示: 负数即小于 0 的数。

输入: 2 行,第一行 n 表示整数的个数,第二行是输入的 n 个整数

输出: 负数的个数。

样例输入: 8 -23 -6 9 -18 -3 4 77 0

样例输出: 4


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

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