PTA-火星数字,最后一个测试点不过。

我的代碼

#include<iostream>
#include<string>
using namespace std;
int main(){
    int N,i,x,a[5],t,j,sum,b[100];
    cin >> N;
    getchar();
    string str;
    string str3;
    const string str1[13] = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
    const string str2[12] = {"tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
    for (i = 0; i < N; i++) {
        getline(cin,str); 
        if (str[0] <= '9' && str[0] >= '0') {
            for (j = 0, x = 0; j <= str.length() - 1; j++) {
                for (t = 0, sum = (str[j] - '0'); t < str.length()-j-1; t++) {
                    sum = sum * 10;
                }
                x += sum;
            }
            t = 0;
            if (x < 13) {
                goto flag1;
            }
            else {
                while (x != 0) {
                    if (x % 13 != 0) {
                        a[t] = x % 13;
                    }
                    else {
                        a[t] = 0;
                    }
                    x = x / 13;
                    t++;
                }
                goto flag2;
            }
            flag1:
            for (t = 0; t <= 12; t++) {
                if (t == x) {
                    cout << str1[t] << endl;
                    break;
                }
            }
            continue;
            flag2:
            for (j = 0; j < 12; j++) {
                if (a[1] - 1 == j) {
                    str3 = str2[j];
                    break;
                }
            }
            for (j = 1; j <= 12; j++) {
                if (a[0] == j) {
                    str3 += " "+str1[j];
                    break;
                }
            }
            cout << str3 << endl;
        }else {
            if (str.length() == 3) {
                for (j = 0; j < 12; j++) {
                    if (str == str1[j]) {
                        cout << j << endl;
                        break;
                    }
                }
                for (j = 0; j < 12; j++) {
                    if (str == str2[j]) {
                        cout << 13 * (j + 1) << endl;
                        break;
                    }
                }
            }else{
                t = 0;
                str3 = str.substr(t, 3);
                for (j = 1; j <= 12; j++) {
                    if (str3 == str1[j]) {
                        cout << j << endl;
                        break;
                    }
                }
                if (j <= 12) {
                    continue;
                }
                for (j = 0; j < 12; j++) {
                    if (str3 == str2[j]) {
                        x = 13 * (j + 1);
                        break;
                    }
                }
                if (j < 12) {
                    t += 4;
                    str3 = str.substr(t, 3);
                    for (j = 1; j <= 12; j++) {
                        if (str3 == str1[j]) {
                            cout << j+x << endl;;
                            break;
                        }
                    }
                }
                else {
                    cout << 0 << endl;;
                }
            }
        }
    }
    return 0;
}

下面为提交结果:

img

煩死了,測試點4就是不過;

img