出现次数 哈希表
問題描述
依次讀入 N(0 < N < 1,000,000)個整數( <=2×109
),計算每個數是第幾次出現。
樣例輸入
10 10 30 20 1 1 30 30 20 2 1樣例輸出
1 1 1 1 2 2 3 2 1 3限制和約定
時間限制:1s
空間限制:128MB
#include<cstdio> #include<cmath> using namespace std; int p=1000007,a[1000001]={0},first[1000008]={0},next[1000001],noat[1000001]; int main() {int n;scanf("%d",&n);for(int i=1;i<=n;i++){bool found=false;scanf("%d",&a[i]);int s=a[i]%p;for(int j=first[s];j>0;j=next[j]){if(a[i]==a[j]){found=true;noat[i]=noat[j]+1;noat[j]++;break;}}if(found==false) {next[i]=first[s];first[s]=i;}printf("%d ",noat[i]+1);}return 0; }?
轉載于:https://www.cnblogs.com/hfang/p/11240025.html
總結
- 上一篇: 集合 哈希表
- 下一篇: 单词背诵【CodeVS3013】 哈希