1100.Mars Numbers (20)...to be continued...

1100.Mars Numbers (20)…to be continued…

pat-al-1100

2017-02-20

  • 之前在乙级做过一遍,但是写的特别麻烦,这次参考书上优化了一下
  • 因为数的范围不大,选择使用map工具以及打表的方式
  • atof:字符串转换成浮点数,在stdlib.h中
  • c_str():从string转成char数组
/**
 * pat-al-1100
 * 2017-02-20
 * Cpp version
 * Author: fengLian_s
 */
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<map>
#include<string>
using namespace std;
string unitDigit[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string tenDigit[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string num2Str[170];
map<string, int> str2Num;
void init()
{
  for(int i = 0;i < 13;i++)
  {
    num2Str[i] = unitDigit[i];//个位0~12,十位0
    str2Num[unitDigit[i]] = i;
    num2Str[i*13] = tenDigit[i];//个位0,十位0~12
    str2Num[tenDigit[i]] = i*13;
  }
  for(int i = 1;i < 13;i++)//十位
  {
    for(int j = 1;j < 13;j++)//个位
    {
      string str = tenDigit[i] + " " + unitDigit[j];
      num2Str[i*13+j] = str;
      str2Num[str] = i*13+j;
    }
  }
}
int main()
{
  init();
  freopen("in.txt", "r", stdin);
  int n;
  scanf("%d\n", &n);
  for(int i = 0;i < n;i++)
  {
    string str;
    getline(cin, str);
    //cout << "str = " << str << endl;
    if(str[0] >= '0' && str[0] <= '9')
    {
      int num = (int)atof(str.c_str());
      cout << num2Str[num] << endl;
    }
    else
      cout << str2Num[str] << endl;
  }
  return 0;
}

-TBC-

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值