
問題連結
CCF201412-1。
問題描述:
輸入數量和記錄,輸出目前記錄是第幾次出現
問題分析:
可以使用哈希表,建立數組,數組下标為記錄,數組元素為次數,依次輸出即可。
解法二:建立數組a存儲記錄,數組b存儲次數,此解法較為繁瑣,本題解不再贅述。
程式說明:
送出後得100分的C++程式如下:
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1010;
int n;
int a[N] = {0};
int main()
{
cin >> n;
while(n--)
{
int x;
cin >> x;
a[x]++;
cout << a[x] << " ";
}
return 0;
}