pat乙级1044提交之后一直说格式错误,求解

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
//火星数字
int main()
{
    char str1[12][10] = {"jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    char str2[12][10] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    string s1, s2;
    int n, num1, num2;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        num1 = num2 = 0;
        cin >> s1;
        char c = cin.get();
        if(c != '\n')//不只输入一个火星文
                cin >> s2;
        if(s1[0] <= '9' && s1[0] >= '0')//输入的是地球文
        {
            int temp;
            temp = atoi(&s1[0]);//讲字符串转换成数字
            if(temp != 0)
            {
                if(temp <= 12)//如果小于13只输出一位
                    cout << str1[temp % 13 - 1] << endl;//以十三进制输出
                else
                    cout << str2[temp / 13 % 13 - 1] << " " << str1[temp % 13 - 1] << endl;


            }
            else
                cout << "tret" << endl;
        }
        else//输入的是火星文
        {
            for(int j = 0; j < 12; j++)
            {
                if(c != '\n')//如果输入了两个字符串
                {
                    if(!strcmp(&s1[0], str2[j]))//判断火星文的高位
                        num1 = (j + 1) * 13;//计算十三进制的高位转换为十进制
                    if(!strcmp(&s2[0], str1[j]))//判断火星文的低位
                        num2 = j + 1;//计算十三进制的低位转换为十进制
                }
                else//只有一个字符串
                {
                    if(!strcmp(&s1[0], str2[j]))
                        num1 = (j + 1) * 13;
                    if(!strcmp(&s1[0], str1[j]))
                        num2 = j + 1;
                }
            }
            num1 += num2;
            cout << num1 << endl;
        }
    }
    return 0;
}
发布了10 篇原创文章 · 获赞 15 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/long_long_later/article/details/79639039