PAT (Advanced Level) 1100. Mars Numbers (20)

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT (Advanced Level) 1100. Mars Numbers (20)相关的知识,希望对你有一定的参考价值。

简单题。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;

char a[20][6]={
    "tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"
};

char b[20][6]={
    "zzz","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"
};

int main()
{
    int n; char s[10000];
    scanf("%d",&n); getchar();
    for(int i=1;i<=n;i++)
    {
        gets(s);
        if(s[0]>=0&&s[0]<=9)
        {
            int num=0;
            for(int i=0;s[i];i++) num=num*10+s[i]-0;
            if(num<=12) printf("%s\n",a[num]);
            else if(num%13==0) printf("%s\n",b[num/13]);
            else printf("%s %s\n",b[num/13],a[num%13]);
        }
        else
        {
            int p=-1;
            for(int i=0;s[i];i++) if(s[i]== ) p=i;
            if(p==-1)
            {
                int num=0;
                for(int i=0;i<=12;i++)
                    if(strcmp(a[i],s)==0) num=i;
                for(int i=1;i<=12;i++)
                    if(strcmp(b[i],s)==0) num=13*i;
                printf("%d\n",num);
            }
            else
            {
                int num=0;
                char op[10]; int sz=0;
                for(int i=0;i<p;i++) op[sz++]=s[i]; op[sz]=0;
                for(int i=1;i<=12;i++)
                    if(strcmp(b[i],op)==0) num=13*i;
                sz=0;
                for(int i=p+1;s[i];i++) op[sz++]=s[i]; op[sz]=0;
                for(int i=0;i<=12;i++)
                    if(strcmp(a[i],op)==0) num+=i;
                printf("%d\n",num);
            }
        }
    }
    return 0;
}

 

以上是关于PAT (Advanced Level) 1100. Mars Numbers (20)的主要内容,如果未能解决你的问题,请参考以下文章

1100. Mars Numbers (20)字符串处理——PAT (Advanced Level) Practise

1100. Mars Numbers (20)字符串处理——PAT (Advanced Level) Practise

PAT (Advanced Level) 1025. PAT Ranking (25)

PAT Advanced Level 1044

PAT Advanced Level 1043

PAT Advanced Level 1079