close

題目連結:  https://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=50115

題目大意:  找出連續的最長長度

思路:  數字0~9,直接用counting sort計算出現次數,最後在看陣列0~9數值哪個最大,輸出。

水題。O(N)

代碼:

#include <bits/stdc++.h>

using namespace std;
int fre[12];

int main()
{
    int m, n, x;
    cin >> m;
    while(m--){
        cin >> n;
        memset(fre, 0, sizeof fre);
        for(int i = 0; i < n; ++i){
            cin >> x;
            fre[x]++;
        }
        int mx = 0;
        for(int i = 0; i < 10; ++i){
            mx = max(mx, fre[i]);
        }
        cout << mx << endl;
    }
    return 0;
}

arrow
arrow
    創作者介紹
    創作者 尾玉 的頭像
    尾玉

    louisfghbvc的部落格

    尾玉 發表在 痞客邦 留言(0) 人氣()