pat1100

题目链接:
pat1100(A)
本题需要注意字符串的处理,尤其是在火星上类似13 ,26这样的数个位的0是不输出的,一定要注意这一点


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    static HashMap<String, Integer> map1;
    static HashMap<String, Integer> map2;
    static String[] mars1={"tret","jan", "feb", "mar", "apr", "may", "jun", 
        "jly", "aug", "sep", "oct", "nov", "dec"};
    static String[] mars2={"tret","tam", "hel", "maa", "huh", "tou", "kes",
        "hei", "elo", "syy", "lok", "mer", "jou"};
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<String> ar=new ArrayList<String>();
        map1=new HashMap<String, Integer>();
        map2=new HashMap<String, Integer>();
        for(int i=0;i<=12;i++){
            map1.put(mars1[i], i);
            map2.put(mars2[i], i);
        }
        int num=0;
        while(true){
            String s=sc.nextLine();
            if(s.length()==0) continue;
            if(s.toCharArray()[0]>='0' &&s.toCharArray()[0]<='9')
                ar.add(f1(s));
            else
                ar.add(f2(s));
            num++;
            if(num==n) break;
        }

        for(int i=0;i<ar.size();i++)
            System.out.println(ar.get(i));
    }
    public static String f1(String s){
        Integer ii=new Integer(s);
        int a=ii%13;
        int b=ii/13;
        String r="";
        if(b==0)
            r+=mars1[a];
        else{
            if(a==0)
                r+=mars2[b];
            else{
            r+=mars2[b];
            r+=" ";
            r+=mars1[a];
            }
        }
        return r;
    }
    public static String f2(String s){
        String[] ss=s.split(" ");
        String r="";
        if(ss.length==1){
            int t;
            if(map1.get(s)==null){
                t=map2.get(s);
                r+=t*13;
            }
            else{
                t=map1.get(s);
                r+=t;
            }

        }
        else{
            int t1;
            int t2;
            if(map1.get(ss[0])==null){
                t2=map2.get(ss[0]);
                t1=map1.get(ss[1]);
            }
            else{
                t2=map2.get(ss[1]);
                t1=map1.get(ss[0]);
            }
            r+=(t2*13+t1);
        }
        return r;
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值