#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; }
共 5 条回复
乘起来的结果很大,所以,你需要在计算过程中判断是否大于100000, scanf 读入 long long 要用 %lld
恩,确实。
#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
不开long long 见祖宗