Source:

PAT A1100 Mars Numbers (20 分)

Description:

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.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer N (<). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.

Output Specification:

For each number, print in a line the corresponding number in the other language.

Sample Input:

  1. 4
  2. 29
  3. 5
  4. elo nov
  5. tam

Sample Output:

  1. hel mar
  2. may
  3. 115
  4. 13

Keys:

  • 哈希映射

Attention:

  • getline()会吸收换行符

Code:

  1. /*
  2. 题目大意:
  3.  
  4. */
  5. #include<cstdio>
  6. #include<string>
  7. #include<map>
  8. #include<iostream>
  9. using namespace std;
  10. const int M=;
  11. map<string,int> earth;
  12. string mars0[M]={"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
  13. string mars1[M]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
  14.  
  15. int main()
  16. {
  17. #ifdef ONLINE_JUDGE
  18. #else
  19. freopen("Test.txt", "r", stdin);
  20. #endif // ONLINE_JUDGE
  21.  
  22. for(int i=; i<M; i++)
  23. earth[mars0[i]]=i;
  24. for(int i=; i<M; i++)
  25. earth[mars1[i]]=i*M;
  26.  
  27. int n;
  28. scanf("%d\n", &n);
  29. while(n--)
  30. {
  31. string s;
  32. getline(cin,s);
  33. if(s[]<'' || s[]>'')
  34. {
  35. if(s.size()==)
  36. printf("%d\n", earth[s]);
  37. else
  38. printf("%d\n", earth[s.substr(,)]+earth[s.substr(,)]);
  39. }
  40. else
  41. {
  42. int num = atoi(s.c_str());
  43. if(num%M!= && num/M!=)
  44. printf("%s %s\n", mars1[num/M].c_str(),mars0[num%M].c_str());
  45. else if(num/M!=)
  46. printf("%s\n", mars1[num/M].c_str());
  47. else
  48. printf("%s\n", mars0[num%M].c_str());
  49. }
  50. }
  51.  
  52. return ;
  53. }

PAT_A1100#Mars Numbers的更多相关文章

  1. PAT1100:Mars Numbers

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  2. PAT 1100 Mars Numbers[难]

    1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...

  3. pat1100. Mars Numbers (20)

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  4. PAT甲级——1100 Mars Numbers (字符串操作、进制转换)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...

  5. pat 1100 Mars Numbers(20 分)

    1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...

  6. 1100 Mars Numbers——PAT甲级真题

    1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...

  7. 1100. Mars Numbers (20)

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  8. A1100. Mars Numbers

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  9. 1100 Mars Numbers(20 分)

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

随机推荐

  1. linux svn 服务器搭建问题

    我的svn版本 svn, version 1.7.14 (r1542130) compiled Nov 20 2015, 19:25:09 Copyright (C) 2013 The Apache ...

  2. webbrowser 防止读取 缓存

    http://bbs.csdn.net/topics/240011502 引用 3 楼 kelei0017 的回复: Delphi(Pascal) codeprocedure TInformation ...

  3. Html5 学习笔记 【PC固定布局】 实战3 热门旅游展示区

    最终效果图: html 代码: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta char ...

  4. Python字节码与解释器学习

    参考:http://blog.jobbole.com/55327/ http://blog.jobbole.com/56300/ http://blog.jobbole.com/56761/ 1. 在 ...

  5. 在WSL Ubuntu 下编译UPX详细步骤

    准备环境: 1. sudo apt-get update 2. sudo apt-get clang 3. apt-get install libstdc++-dev Reading package ...

  6. 【计算机网络】两个网络模型——OSI参考模型和TCP/IP模型

    计算机网络 两个网络模型 计算机网络模型 分层机制----规划通讯细节 层与层之间之间是独立的.屏蔽的,下层为上层提供服务. 一些概念 实体: 任何发送/接收信息的软件/硬件进程. 对等层: 两个不同 ...

  7. RSA加密、解密实现原理

    RSA加密.解密实现原理 1.公钥.私钥

  8. 转 使用Python的logging.config.fileConfig配置日志

    Python的logging.config.fileConfig方式配置日志,通过解析conf配置文件实现.文件 logglogging.conf 配置如下: [loggers]keys=root,f ...

  9. python基础----斐波那契数列

    python实现斐波那契数列的三种方法 """ 斐波那契数列 0,1,1,2,3,5,8,13,21,... """ # 方法一:while ...

  10. 在Ubuntu custom kernel上裝perf by compile

    Using perf, the Linux Performance Analysis tool on Ubuntu Karmic A lot has been going on with Linux ...