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;
}
时间: 2024-10-10 11:09:08

PAT (Advanced Level) 1100. Mars Numbers (20)的相关文章

PAT甲级题解-1100. Mars Numbers (20)-字符串处理

没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是"hel",而不是"hel tret". 代码: #include <iostream> #include <cstdio> #include <algorithm> #include <map> #include <string> #include <string.h> using namespace s

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

题目信息 1100. Mars Numbers (20) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep,

1100. Mars Numbers (20)

People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively. For the next higher dig

PAT (Advanced Level) 1096. Consecutive Factors (20)

如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; long long n; bool prime(

PAT (Advanced Level) 1081. Rational Sum (20)

简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; struct FenShu { long l

PAT (Advanced Level) 1084. Broken Keyboard (20)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; const int maxn=100000; char s[maxn],t[maxn],u[m

PAT (Advanced Level) 1112. Stucked Keyboard (20)

找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; int k;

PAT (Advanced Level) 1073. Scientific Notation (20)

简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; char s[100000]; int p;

PAT (Advanced Level) 1088. Rational Arithmetic (20)

简单题. 注意:读入的分数可能不是最简的.输出时也需要转换成最简. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algor