Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
108023 | 刘子锐 | 找最大的数 | C++ | Compile Error | 0 MS | 0 KB | 955 | 2025-01-19 13:44:00 |
#include<bits/stdc++.h> using namespace std; int main() { //数组 int n=10; int a[n]; //数组的输入 for (int i = 0; i < n; i++) { cin >> a[i]; } //数组求和:累加器 int sum = 0; for (int i = 0; i <= n - 1; i++) { sum = sum + a[i]; } cout << sum << endl; //求平均数 float p = sum * 1.0 / n; printf("%.2f", p); cout << endl; //求大于平均数的和:累加器 int c = 0; for (int i = 0; i <= n - 1; i++) { if (a[i] > max) { max=a[i]; index=i; } } cout << c << endl; } cout << count << endl; //输出所有大于平均数 for (int i = 0; i <= n - 1; i++) { if (a[i] > p) { cout << a[i] << " "; } } //求最大值:计数器 int max = a[0] ; //第1个计数器记录最大值本身 int index = 0; // 第2个计数器下标 for(int i=0;i<=n-1;i++){ if (a[3] > max) { max = a[3]; index = 3; } } cout<<max<<" "<<index; return 0; }
Main.cc: In function 'int main()': Main.cc:26:14: error: invalid operands of types 'int' and '' to binary 'operator>' if (a[i] > max) { ^ Main.cc:27:7: error: overloaded function with no contextual type information max=a[i]; ^ Main.cc:28:9: error: overloaded function with no contextual type information index=i; ^ Main.cc: At global scope: Main.cc:33:2: error: 'cout' does not name a type cout << count << endl; ^ Main.cc:35:2: error: expected unqualified-id before 'for' for (int i = 0; i <= n - 1; i++) { ^ Main.cc:35:18: error: 'i' does not name a type for (int i = 0; i <= n - 1; i++) { ^ Main.cc:35:30: error: 'i' does not name a type for (int i = 0; i <= n - 1; i++) { ^ Main.cc:41:12: error: 'a' was not declared in this scope int max = a[0] ; //第1个计数器记录最大值本身 ^ Main.cc:42:6: error: 'int index' redeclared as different kind of symbol int index = 0; // 第2个计数器下标 ^ In file included from /usr/include/c++/5/cstring:42:0, from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:48, from Main.cc:1: /usr/include/string.h:477:1: note: previous declaration 'const char* index(const char*, int)' index (const char *__s, int __c) __THROW ^ Main.cc:44:1: error: expected unqualified-id before 'for' for(int i=0;i<=n-1;i++){ ^ Main.cc:44:13: error: 'i' does not name a type for(int i=0;i<=n-1;i++){ ^ Main.cc:44:20: error: 'i' does not name a type for(int i=0;i<=n-1;i++){ ^ Main.cc:50:3: error: 'cout' does not name a type cout<