zoukankan      html  css  js  c++  java
  • 1100 Mars Numbers 字符串操作

    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:

    4
    29
    5
    elo nov
    tam
    

    Sample Output:

    hel mar
    may
    115
    13
    
    #include<iostream>
    #include<map>
    #include<string>
    using namespace std;
    string s;
    int m;
    string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
    string b[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
    void f1()
    {
        int res=0,i=0;
        int n=s.size();
        while(i<n)
        {
            res=res*10+(s[i++]-'0');
        }
        int t=res;
        if (t / 13) cout << b[t / 13];
        if ((t / 13) && (t % 13)) cout << " ";
        if (t % 13 || t == 0) cout << a[t % 13];
    }
    void f2()
    {
        string s1,s2;
        int t1=0,t2=0;
        s1=s.substr(0,3);
        int n=s.size();
        if(n>4)
        s2=s.substr(4,3);
        for (int j = 1; j <= 12; j++) {
            if (s1 == a[j] || s2 == a[j]) t2 = j;
            if (s1 == b[j]) t1 = j;
        }
        cout << t1 * 13 + t2;
    }
    int main()
    {
        cin>>m;
        getchar();
        while(m--)
        {
        getline(cin,s);
        if('0'<=s[0]&&s[0]<='9')
        f1();
        else
        f2();
        cout<<endl;
       }
        return 0;
     } 
    如果你够坚强够勇敢,你就能驾驭他们
  • 相关阅读:
    sqlserver实现树形结构递归查询(无限极分类)
    我所理解的Delphi中的数组类型
    Delphi CreateMutex 防止程序多次运行
    CreateMutex和WaitForSingleObject组合的有关问题
    SqlServer 递归查询树形数据
    XE5 Android 开发实现手机打电话和发短信 [转]
    ShowModal在FireMonkey移动应用程序对话框
    xe5 android 控制蓝牙[转]
    xe5 android 调用照相机获取拍的照片[转]
    xe5 android sample 中的 SimpleList 是怎样绑定的 [转]
  • 原文地址:https://www.cnblogs.com/liuzhaojun/p/11221287.html
Copyright © 2011-2022 走看看