1100 Mars Numbers

People on Mars count their numbers with base 13:

Zero on Earth is called "tret" on Mars.
The numbers 1 to 12 on Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively.
For the next higher digit, Mars people name the 12 numbers as "tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou", respectively.
For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.
意思就是说,人们在火星上把1、2、3……叫做"jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec",同时把13的1倍,13的二倍叫做"tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou",其实就是类似于进制转换嘛。
算法笔记上写的感觉太复杂了,还人造hash,感觉没有必要。第二个测试案例总是不通过,不知道为啥。最后在判断

if(str[0]>='0'&& str[0]<='9'){
            EtoM(str);
        }else{
            MtoE(str);
        }

的时候,str[0]>='0'取了个等于号,第二个测试案例就过了。说真的我觉得也很奇葩,肯定是有05 07这样的数来考验大家了
附上代码,肯定是AC啦

#include
#include
using namespace std;
int n;
string low[13]={"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string high[13]={"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};


int change(string word)
{
    for(int i = 0; i < 13; i++){//0~13
        if(low[i]==word) return i;
    }
    for(int i = 0; i < 13; i++){//0~13
        if(high[i]==word) return i*13;
    }
}
void MtoE(string str){
    string word;
            int ans = 0;
            for(int i = 0; i < str.size(); i++){
                if(str[i]!=' '){
                    word += str[i];
                }
                else {
                    ans += change(word);
                    word = "";
                }
            }
            ans += change(word);
            printf("%d\n",ans);
}

void EtoM(string str){
    int cnum=0;
    int slen=str.size();
    for(int i=0;i='0'&& str[0]<='9'){
            EtoM(str);
        }else{
            MtoE(str);
        }
    }
    
    return 0;
}

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