zoukankan      html  css  js  c++  java
  • 【PAT】B1044 火星数字(20 分)

    /*
    火星文有两位,第二位为0不输出
    
     
     */
    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    #include<ctype.h>
    
    using namespace std;
    char arr[20]={0};
    char data[13][2][5]={
    {"tret","tret"},
    {"jan","tam"},
    {"feb","hel"},
    {"mar","maa"},
    {"apr","huh"},
    {"may","tou"},
    {"jun","kes"},
    {"jly","hei"},
    {"aug","elo"},
    {"sep","syy"},
    {"oct","lok"},
    {"nov","mer"},
    {"dec","jou"}
    };
    void prr(char *str){
        if(str[3]=='t'&&str[0]=='t'&&str[1]=='r'&&str[2]=='e'){
            printf("0");return;
        }
        if(islower(str[0])){//输入为火星文
            int high=0,low=0;
            for(int i=0;i<13;i++){
                if(data[i][1][0]==str[0]&&data[i][1][1]==str[1]&&data[i][1][2]==str[2])//前边的字符只可能是高位
                    high+=i*13;
                if(data[i][0][0]==str[0]&&data[i][0][1]==str[1]&&data[i][0][2]==str[2])//后边的字符不确定
                    low+=i;
                if(data[i][0][0]==str[4]&&data[i][0][1]==str[5]&&data[i][0][2]==str[6]&&str[3]!='')
                    low+=i;
            }
            printf("%d",low+high);
        }
        else{//输入为数字
            int temp;
            sscanf(str,"%d",&temp);
            if(temp<13){
                printf("%s",&data[temp][0]);
            }
            else{
                printf("%s",&data[temp/13][1]);
                if(temp%13!=0)
                printf(" %s",&data[temp%13][0]);
            }
        }
    }
    int main(){
        int N;scanf("%d",&N);
        for(int i=0;i<N;i++){
            scanf(" %[^
    ]",arr);
            if(i!=0) printf("
    ");
            prr(arr);
        }
        return  0;
    }
    
    
  • 相关阅读:
    Python 类的特性讲解
    Python 类的式列化过程解剖
    Python 面向对象介绍
    Python subprocess模块
    Python re模块
    Python configparser模块
    Python pyYAML模块
    Python logging模块
    Python hashlib模块
    OAuth2.0 错误码
  • 原文地址:https://www.cnblogs.com/hebust/p/9498019.html
Copyright © 2011-2022 走看看