zoukankan      html  css  js  c++  java
  • C++ STL map B1044/A1100.火星数字(读取带空格的string : 使用getline(cin,str)函数)

    用了打表的技巧

    #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];//个位为[0,12],十位为0
            strToNum[unitDigit[i]] = i;
            numToStr[i * 13] = tenDigit[i];//十位为[0,12],个位为0
            strToNum[tenDigit[i]] = i * 13;
        }
        for(int i = 1;i<13;++i){
            for(int j = 1;j<13;++j){
                string str = tenDigit[i] + " " + unitDigit[j];
                numToStr[i * 13 + j] = str;//数字——>火星文
                strToNum[str] = i * 13 + j; //火星文——>数字
            }
        }
    }
    int main(){
        init();//打表
        int T;
        scanf("%d%*c",&T);
        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;
    } 
  • 相关阅读:
    [bzoj1064][Noi2008]假面舞会
    [bzoj1503][NOI2004]郁闷的出纳员
    [bzoj1758][Wc2010]重建计划
    [bzoj1588][HNOI2002]营业额统计
    [bzoj2423][HAOI2010]最长公共子序列
    [3.26福建四校联考]
    [51nod1238]最小公倍数之和V3
    [bzoj2301] [HAOI2011]Problem b
    [hdu5608]function
    [51nod1239欧拉函数之和]
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12203365.html
Copyright © 2011-2022 走看看