zoukankan      html  css  js  c++  java
  • PAT 1044 火星数字

    https://pintia.cn/problem-sets/994805260223102976/problems/994805279328157696

    火星人是以13进制计数的:

    • 地球人的0被火星人称为tret。
    • 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
    • 火星人将进位以后的12个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。

    例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字“115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。

    输入格式:

    输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 —— 或者是地球文,或者是火星文。

    输出格式:

    对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

    输入样例:

    4
    29
    5
    elo nov
    tam
    

    输出样例:

    hel mar
    may
    115
    13
    
     
    #include <bits/stdc++.h>
    
    using namespace std;
    
    int cmpchar(const char* a,const char* b)
    {
        int lena=strlen(a);
        int lenb=strlen(b);
        if(lena!=lenb)
            return 0;
        else
        {
            for(int i=0; i<lena; i++)
            {
                if(a[i]!=b[i])
                    return 0;
            }
        }
        return 1;
    }
    
    char s[10],c[5];
    //第一个出来对应 ge
    char ge[15][15]= {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    //第二个出来对应 shi
    char shi[15][15]= {"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    char a[15][15];
    
    int main()
    {
        int T;
        scanf("%d",&T);
        getchar();
        for(int i=1; i<=T; i++)
        {
            cin.getline(s,10);
            int len=strlen(s);
            int num=0;
            int ans=0,sum1=0;
            int flag=0;
            if(s[0]>='0'&&s[0]<='9')
            {
                for(int i=0; i<len; i++)
                num=num*10+s[i]-'0';
                if(num<13)
                    cout<<ge[num]<<endl;
                else if(num%13==0)
                {
                    cout<<shi[num/13]<<endl;
                }
                else
                {
                    cout<<shi[num/13%13]<<" "<<ge[num%13]<<endl;
                }
            }
            else
            {
                s[len]=' ';
                s[len+1]='';
                for(int i=0; i<len+1; i++)
                {
                    if(s[i]!=' ')
                        for(int j=i; j<len+1; j++)
                        {
                            if(s[j]!=' ')
                                continue;
                            else
                            {
                                ans++;
                                for(int k=i; k<j; k++)
                                {
                                    a[ans][k-i]=s[k];
                                }
                                a[ans][j-i]='';
                                i=j;
                                break;
                            }
                        }
                }
                for(int i=0; i<=14; i++)
                {
                    if(ans==1)
                    {
                        if(cmpchar(a[1],ge[i])==1)
                            cout<<i<<endl;
                        else if(cmpchar(a[1],shi[i])==1)
                            cout<<13*i<<endl;
                    }
                    else if(ans==2)
                    {
                        flag=1;
                        if(cmpchar(a[1],shi[i])==1)
                            sum1+=13*i;
                        if(cmpchar(a[2],ge[i])==1)
                            sum1+=i;
                           // cout<<sum1<<endl;
                    }
                }
                    if(flag==1)
                        cout<<sum1<<endl;
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    HDU4311 Meeting point1 曼哈顿距离快速计算
    POJ1681 Painter's Problem 高消
    解决FLASH遮住DIV层的方法
    jcarousellite jQuery实现滚动的图片
    js中escape,encodeURI,encodeURIComponent三个函数的区别
    clear:both; 用法 什么时候用
    IE6下使网页png图片透明显示
    jqueryautocomplete 使用手册
    jquery获得select option的值 和对select option的操作
    jquery1.6获取checkbox的选中状态
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9339623.html
Copyright © 2011-2022 走看看