zoukankan      html  css  js  c++  java
  • PAT 甲级 1100 Mars Numbers (20 分)

    思路:

    分4种情况:
    (1)为0或tret;
    (2)输入为阿拉伯数字,除13加上取余13即可;
    (3)输入为长度为3的字符串,可能是高位也可能是低位;
    (4)输入为长度为7的字符串,高位*13+低位;

    代码:

    #include<iostream>
    #include<cstdlib>
    #include<string>
    #include<map>
    using namespace std;
    int main(){
    	int n;
    	cin>>n;
    	cin.ignore();
    	string low[]={"","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    	string high[]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    	map<string,int> lw,hg;
    	for(int i=0;i<=12;i++) lw[low[i]]=hg[high[i]]=i;
    	for(int i=0;i<n;i++){
    		string s;
    		getline(cin,s);
    		if(s=="0"||s=="tret") cout<<(s=="0"?"tret
    ":"0
    ");
    		else if(s[0]>='0'&&s[0]<='9'){
    			int num=stoi(s);
    			string str=num>13&&num%13!=0?" ":"";
    			cout<<high[num/13]+str+low[num%13]<<endl;
    		}
    		else if(s.length()==3) cout<<hg[s]*13+lw[s]<<endl;
    		else cout<<hg[s.substr(0,3)]*13+lw[s.substr(4,3)]<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    python-禅
    学习思路(待完善)
    思考-想法-研究生
    五一前随笔
    监督学习,非监督学习和半监督学习
    第二章maven的安装和配置
    maven实战 第一章
    常用接口测试工具
    jmeter监控服务器性能(转载)
    数据库操作
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12309037.html
Copyright © 2011-2022 走看看