样例能过,交上去RE。。

题目总版

wky_wsy @ 2024-11-24 12:48:07

原题链接
REEEEEEEEE

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;
int n;
int a,t[1007];
signed main(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a);
        t[a]++;
    }
    for(int i=0;i<1007;i++){
        if(t[i]!=0){
            printf("%lld %lld\n",i,t[i]);
        }
    }
    return 0;
}

by 11ofjay @ 2024-11-24 13:16:47

数组开小了 @wky_wsy


by 11ofjay @ 2024-11-24 13:16:59

@wky_wsy


by 11ofjay @ 2024-11-24 13:17:27

怎么 AT 不了?


by 11ofjay @ 2024-11-24 13:17:37

@wky_wsy .


by 11ofjay @ 2024-11-24 13:18:44

用 STL 的映射来做,因为数据范围 10^9 容易爆啊。


by 11ofjay @ 2024-11-24 13:20:23

@wky_wsy 要不然就排序找也行,纯下标计数过不了的。


by 11ofjay @ 2024-11-24 13:27:55

#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> a;
signed main(){
    int n;
    cin>>n;
    for(int i=1,x;i<=n;i++){
        cin>>x;
        a[x]++; 
    }
    map<int ,int >::iterator it;

    for(it=a.begin();it!=a.end();it++){
        cout<<it->first<<" "<<it->second<<endl;
    }

    return 0;
} 

|