STL-PAT-A1100 & B.1044 [string & map]
2017-03-05 11:45
344 查看
思路:
1、使用getline(cin, str) 读入一行时,注意不要读入换行符哪!
2、map【string, int】 中string可以带空格
1、使用getline(cin, str) 读入一行时,注意不要读入换行符哪!
2、map【string, int】 中string可以带空格
/**********************3stone***************************** Problem: PAT.A1100.火星数字(20) Author:3stone Time:2017/3/5 ***********************3stone****************************/ #include<cstdio> #include<iostream> #include<cstring> #include<string> #include<map> using namespace std; string low[14] = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"}; string high[14] = {"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"}; string etom[300]; map<string, int> mtoe; int main(){ for(int i = 0; i < 13; i++){//初始化 mtoe[low[i]] = i; mtoe[high[i]] = i * 13; etom[i] = low[i]; etom[i * 13] = high[i]; } for(int i = 1; i < 13; i++)//组成火星文的两位数【赞】 for(int j = 1; j < 13; j++){//个位 string str = high[i] + " " + low[j]; etom[i * 13 + j] = str; mtoe[str] = i * 13 + j; } int n; scanf("%d%*c", &n); string str; for(int i = 0; i < n; i++){ int num = 0; getline(cin, str); if(str[0]>='0' && str[0] <= '9'){//数字 for(int j = 0; j < str.length();j++) num = num * 10 + (str[j] - '0'); printf("%s\n", etom[num].c_str()); // cout << etom[num] << endl; } else{//火星 //怎样判断是一位数还是两位数呢 cout << mtoe[str] << endl; } }//for-i return 0; }
相关文章推荐
- 【南理oj】991 - Registration system(STL - map & string)
- 【ny-oj】-1112-求次数(STL,string&map)
- 【杭电oj】2072 - 单词数(STL - string & map)
- 【南理oj】1112 - 求次数(STL - map & string)
- STL review:vector & string & map & struct
- 入门计划->学用stl std::map<std::string, int>
- 【HDU】1251 - 统计难题(字典树 || STL - map & string)
- STL map<string,string> 未能从“const std::string”为“const std::_Revranit<_RanIt,_Base> &”推导 模板 参数
- stl::map的比较函数(less, <)
- 用EL表达式获取List<Map<String,Object>>里面的值
- velocity 循环Map<String,Map<String,Long>>
- STL中map和string, vector 用法详解
- STL基本容器: string、vector、list、deque、set、map
- Gson序列化与反序列化成员变量为Map<String,Object>的类对象
- STL中map和string, vector 用法详解
- List<Map<String, Object>>
- 将一个LIST分组,转为map<string,list>类型
- STL中map和string, vector 用法详解
- STL 基本容器 : string、vector、list、deque、set、map 的区别
- stl几个(set map vector string)用法