1100. Mars Numbers (20)

26 篇文章 0 订阅

1100. Mars Numbers (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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:
4
29
5
elo nov
tam
Sample Output:
hel mar
may
115
13
地球数用的是10进制的阿拉伯数字,
火星数用的是13进制的。且低位表示0~12为tret……dec 而高位13,26,39……13*12为tam……jou。注意,当地球数为13的倍数,只要高位的即可
这次2015pat的20分,考试的时候只过了两个测试点,当时也是下面的思路,应该是/%12、13出现遗漏,还有就是用惯了vs换成vc6有点不熟悉。
 

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户
9月12日 19:23答案正确201100C++ (g++ 4.7.2)1308datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分
0答案正确118012/12
1答案正确13082/2
2答案正确13002/2
3答案正确13082/2
4答案正确11802/2

#include<iostream>   
#include<string>  
using namespace std;
int equelstr(string *mars, string str)
{
  int i;
  for (i = 0; i < 25 && mars[i] != str; i++);
  return i;
}
int main()
{
  string mars[25] = { "tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec",
    "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
  string str,strt;
  int N, num,temp,goal; 
  cin >> N;
  getchar();
  while (N--)
  {
    getline(cin, str);  
    if (str[0] >= '0'&&str[0] <= '9' ) 
    {
      sscanf(str.c_str(), "%d", &num); 
      if (num < 13 || num>12 && num % 13 == 0)
        cout << mars[num%13+(num>12?num/13+12:0)] << endl;
      else 
        cout << mars[num / 13+12] << " " << mars[num % 13] << endl; 
    }
    else 
    {
      temp = str.find(' ');
      if (temp != -1)
      { 
        strt = str.substr(0,3);  
        goal = (equelstr(mars, strt)-12)*13;
        strt = str.substr(temp+1,3); 
        goal += equelstr(mars, strt);
      }
      else
      {
        goal=equelstr(mars, str);
        goal = goal > 12 ? (goal - 12) * 13 : goal;
      } 
      cout << goal << endl; 
    }
  }
  system("pause");
  return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值