先建立一個36的次方表

並且取1688的餘數(否則會overflow)

 

迴圈

輸入執行次數

迴圈

輸入車牌號碼

將車牌號碼轉乘10進位並且取1688的餘數

輸出等第

 

 

#include <iostream>
#include <cctype>

 

 

#define N 100

using namespace std;

int mod36[N];

void setTable()
{
    mod36[0] = 1;
    for(int i = 1; i<N; i++)
        mod36[i] = mod36[i-1]*36%1688;
}

int main()
{
    int T;
    string licensePlate;
    int RANK;

    setTable();

    while(cin >> T)
        while(T--)
        {
            cin >> licensePlate;

            RANK = 0;
            for(int i = licensePlate.length()-1, j = 0; i>=0; i--, j++)
            {
                if(isalpha(licensePlate[i]))
                    licensePlate[i] -= 55;
                else
                    licensePlate[i] -= 48;

                RANK = (RANK+licensePlate[i]*mod36[j])%1688;
            }

            cout << RANK + 1 << endl;
        }
        
    return 0;
}

arrow
arrow
    全站熱搜

    大神(偽) 發表在 痞客邦 留言(0) 人氣()