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;
    }
    
  • 相关阅读:
    PHP获取时间or戳?
    滤镜灰CSS
    css3 文字渐变色
    除指定区域外点击任何地方隐藏DIV
    margin-top bug 处理方案
    基于Bootstrap好用的瀑布流
    初始数据库
    协程
    粘包及解决方案
    log日志的三种方式
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12309038.html
Copyright © 2011-2022 走看看