为什么70分

tctm169 我以逍遥醉人间 2024-05-01 15:32:50 10

#include <bits/stdc++.h> #include #include #include #include #include #include #include using namespace std; int n; int a[10000005]; long long sum = 1; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum *= a[i]; } if (sum > 1000000) cout << ">1000000"; else cout << sum; }

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

共 5 条回复

root 站长

乘起来的结果很大,所以,你需要在计算过程中判断是否大于100000, scanf 读入 long long 要用 %lld

root 站长
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        sum *= a[i];
        {
            if (sum > 1000000) {
                cout << ">1000000";
                return 0;
            }
        }
    }
    cout << sum;
root 站长

恩,确实。

tctm169 我以逍遥醉人间

#include <bits/stdc++.h> #include #include #include #include #include #include #include using namespace std; long long int n; long long int a[10000005]; long long sum = 1; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sum *= a[i]; } if (sum > 1000000) cout << ">1000000"; else cout << sum; }照样70

root 站长

不开long long 见祖宗