如图,我在做csp一道编程题的时候,定义的数组
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[1001];//此处是我定义的数组
int n;
cin>>n;
for(int i=0;i<n;i++){
int temp;
cin>>temp;
a[temp]++;
cout<<a[temp]<<" ";
}
return 0;
}
得到了这样的结果,请问是怎么回事呢?
代码改成这样就没错了
#include<bits/stdc++.h>
using namespace std;
nt a[1001];//此处是我定义的数组
int main(){
i
int n;
cin>>n;
for(int i=0;i<n;i++){
int temp;
cin>>temp;
a[temp]++;
cout<<a[temp]<<" ";
}
return 0;
}
结果
相似问题