C ++ STL map B1044 / A1100 Digital Mars. (Read with spaces string: Use getline (cin, str) function)

With the skills to play table

 

 

#include <bits/stdc++.h>
#include<math.h>
#include <string>
using namespace std;
const int maxn = 40010;//最大学生人数
//[0,12]的火星文
string unitDigit[13]  = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
//13的[0,12]倍的火星文
string tenDigit[13] = {"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
string numToStr[170];//数字——>火星文
map<string,int> strToNum;//火星文——>数字
void init(){
    for(int i =0;i<13;++i){
        numToStr[i] = unitDigit[i];//Bits of [0,12], ten 0 
        strToNum [unitDigit [I]] = I; 
        numToStr [I * 13 is ] = tenDigit [I]; // ten to [0,12], bit 0 
        strToNum [tenDigit [I]] I * = 13 is ; 
    } 
    for ( int I = . 1 ; I < 13 is ; ++ I) {
         for ( int J = . 1 ; J < 13 is ; ++ J) {
             String STR = tenDigit [ I] + "  " + unitDigit [J]; 
            numToStr [I * 13 is + J] = STR; //Digital -> Mars 
            strToNum [STR] I * = 13 is + J; // Mars -> Digital 
        } 
    } 
} 
int main () { 
    the init (); // play table 
    int T; 
    Scanf ( " % D% C * " , & T);
     the while (T-- ) {
         String STR;
         // CIN >> STR; 
        getline (CIN, STR);
         IF (STR [ 0 ]> = ' 0 ' && STR [ 0 ] <= ' . 9 ' ) {
             int num = 0;//字符串转换为数字
            for(int i=0;i<str.length();++i){
                num = num * 10 + (str[i] - '0');
            }
            cout<<numToStr[num]<<endl;
        }else{
            cout<<strToNum[str]<<endl;
        }
    }
    system("pause");
    return 0;
} 

Guess you like

Origin www.cnblogs.com/JasonPeng1/p/12203365.html