max在C++里是一个函数,(应该)不能作为变量使用
by starwind24 @ 2024-04-26 21:46:16
@[starwind24](/user/1279373)
改了也一样:(
by yi18600361898 @ 2024-04-27 10:03:59
@[starwind24](/user/1279373)
[记录](https://www.luogu.com.cn/record/157166582)
by yi18600361898 @ 2024-04-27 10:04:51
改了一下 **20分**
```cpp
#include <bits/stdc++.h>
using namespace std;
int max_a(int a[],int n){
int max=-11;
for(int i=0;i<n;i++){
if(max<a[i]) max=a[i];
}
return max;
}
int main(){
int n,maxn;
cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
maxn=max_a(a,n);
int sum[maxn]={0};
for(int i=0;i<n;i++){
sum[a[i]]++;
}
for(int i=0;i<=maxn;i++){
cout<<sum[i]<<endl;
}
return 0;
}
``````
倒数第五行
```for(int i=0;i<maxn;i++){```
改成了
```for(int i=0;i<=maxn;i++){``````
by yi18600361898 @ 2024-04-27 10:10:02
第16行空间开小了,这样定义只能使用s[1 ~maxn-1],但是在第21行用到了s[maxn+1] @[yi18600361898](/user/1267066)
by lcy666666 @ 2024-05-02 21:18:40
@[yi18600361898](/user/1267066) 你看看我的:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
unsigned int n,b,sum=0;
cin>>n;
unsigned int a[10000000];
cin>>a[0];
b=a[0];
for (int i=1;i<n;i++){
cin>>a[i];
if (a[i]>b) b=a[i];
}
unsigned int poop[b+1];
for(int i=0;i<=b;i++) poop[i]=0;
for (int i=0;i<n;i++){
poop[a[i]]++;
}
for (int i=0;i<=b;i++){
cout<<poop[i]<<endl;
}
}
```
by penguin_is_cool @ 2024-05-02 21:24:00
又改了一下 **70分**
[记录](https://www.luogu.com.cn/record/158048309)
by yi18600361898 @ 2024-05-05 09:50:37
@[lcy666666](/user/491219)
by yi18600361898 @ 2024-05-05 09:51:08