Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
108037 | 刘子锐 | 22不与最大数相同的数字之和 | C++ | Compile Error | 0 MS | 0 KB | 1099 | 2025-01-19 14:10:41 |
#include<bits/stdc++.h> using namespace std; int main() { int n; int w; cin>>n; int a[n]; for(int i=0;i<=n;i++){ cin>>a[i]; } cout<<a[i]<<endl; int sum = 0; for (int i = 0; i <= n - 1; i++) { sum = sum + a[i]; } cout << sum << endl; //数组求和:累加器 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; } } maX=w; } return 0; }
Main.cc: In function 'int main()': Main.cc:11:13: error: 'i' was not declared in this scope cout<' to binary 'operator>' if (a[i] > max) { ^ Main.cc:34:7: error: overloaded function with no contextual type information max=a[i]; ^ Main.cc:35:9: error: overloaded function with no contextual type information index=i; ^ Main.cc:5:9: warning: unused variable 'w' [-Wunused-variable] int w; ^ Main.cc: At global scope: Main.cc:40:2: error: 'cout' does not name a type cout << count << endl; ^ Main.cc:42:2: error: expected unqualified-id before 'for' for (int i = 0; i <= n - 1; i++) { ^ Main.cc:42:18: error: 'i' does not name a type for (int i = 0; i <= n - 1; i++) { ^ Main.cc:42:30: error: 'i' does not name a type for (int i = 0; i <= n - 1; i++) { ^ Main.cc:48:12: error: 'a' was not declared in this scope int max = a[0] ; //第1个计数器记录最大值本身 ^ Main.cc:49: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:51:1: error: expected unqualified-id before 'for' for(int i=0;i<=n-1;i++){ ^ Main.cc:51:13: error: 'i' does not name a type for(int i=0;i<=n-1;i++){ ^ Main.cc:51:20: error: 'i' does not name a type for(int i=0;i<=n-1;i++){ ^ Main.cc:57:2: error: 'maX' does not name a type maX=w; ^ Main.cc:58:1: error: expected declaration before '}' token } ^