A1100.Mars Numbers

//打表进制转换
//10进制转为13进制,只不过13进制的输出方式与常规形式不同,这里采用的是火星文。输入的数据最大只到169,
//也就是说对应的13进制最多只有两位,所以不用使用数组存储每个转化后进制位,直接模拟即可
//
//13进制的火星文转化为10进制,首先获取其字符串的长度。如果其字符串的长度len>4说明
//火星文有两位,从左到右代表13进制的高位和低位。故令s1 = s.substr(0,3),s2 = s.substr(4,3);
//而后遍历两个表,i从1到12,如果有s1 == a[i] || s2 == a[i] 则t2 = i。如果有s1 == b[i]则t1 = i;
//t1,t2默认值均为0,最后输出t1*13 + t2即可。注意如果火星文为"tret",也是成立的,因为此时t1,t2的值
//仍然为0,输出为0正确。 
 
 
#include 
using namespace std;
string a[13] = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string b[13] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo","syy", "lok", "mer", "jou"};
string s;
int len;

void func1(int v) {         //10进制转化为13进制的火星文 
    if(v / 13 == 0) cout<13 
        cout< 4) s2 = s.substr(4,3);
    for(int i = 1;i <= 12;i++) {
        if(a[i] == s1 || a[i] == s2) t2 = i;
        if(b[i] == s1) t1 = i;
    }
    cout<>k;
    getchar();              //消除回车的影响 
    for(int i = 0;i < k;i++) {  
        getline(cin,s);             //完整读入一行 
        len = s.length();
        if(s[0] >= '0' && s[0] <= '9') 
            func1(stoi(s));
        else 
            func2();
        cout<

转载于:https://www.cnblogs.com/Western-Trail/p/10370683.html

你可能感兴趣的:(A1100.Mars Numbers)