1100. Mars Numbers (20)
来源:互联网 发布:mac qq截图存在哪里 编辑:程序博客网 时间:2024/06/15 20:39
People on Mars count their numbers with base 13:
- Zero on Earth is called "tret" on Mars.
- The numbers 1 to 12 on Earch 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 (< 100). 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:4295elo novtamSample Output:
hel marmay11513
#include <iostream>#include <cstring>using namespace std;char lower[13][5] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};char higher[13][5] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};int toNum(char* str){int res = 0;int i = 0;while(str[i] != '\0'){res = res * 10 + str[i] - '0';i++;}return res;}int main(){int count;char all[20];char fir[5], sec[5];scanf("%d", &count);getchar();while(count--){gets(all);strcpy(fir, "");strcpy(sec, "");sscanf(all, "%s", fir);if(fir[0] >= '0' && fir[0] <= '9'){int num = toNum(fir);int shi = num / 13;int ge = num % 13;if(shi > 0){printf("%s",higher[shi]);}if(shi > 0 && ge > 0){printf(" ");}if(ge > 0 || shi == 0){printf("%s\n", lower[ge]);}else{printf("\n");}}else{int res = 0;sscanf(&all[strlen(fir)], "%s", sec);for (int i = 1; i < 13; ++i){if(strcmp(higher[i], fir) == 0){res = i * 13;strcpy(fir, sec);break;}}for(int i = 0; i < 13; i++){if(strcmp(lower[i], fir) == 0){res += i;break;}}printf("%d\n", res);}}return 0;}
阅读全文
0 0
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 工程师开发流程规范
- 循环队列--击鼓传花或者叫烫手的山芋(hot potato)
- memcached
- 使用LAYUI父页面向子页面传参
- 接上一个webpack资源整合。我觉得这样更清晰
- 1100. Mars Numbers (20)
- 深度框架概述
- 代码混淆
- http://blog.csdn.net/lengshine/article/details/5470545
- 浅谈Java项目日志记录和分析 (基于log4j介绍)
- js原生-倒计时
- 实例解析lua中的socket(TCP,UDP)
- android在Service,BroadCast onReceiver()中弹出Dialog对话框(即全局性对话框 )
- 真正的高手,都是在高价值区,做正确的事