1100. Mars Numbers (20) "String Processing"--pat (Advanced level) practise

Source: Internet
Author: User

Topic Information

1100. Mars Numbers (20)

Time limit MS
Memory Limit 65536 KB
Code length limit 16000 B
People on Mars count their numbers with base 13:

Zero on Earth was called "Tret" on Mars.
The numbers 1 to earch are called "Jan, Feb, Mar, Apr, May, June, Jly, Mar, Sep, Oct, Nov, Dec" on Mars, respectively.
For the next higher digit, Mars people name the numbers as "Tam, Hel, Maa, huh, tou, Kes, Hei, ELO, Syy, Lok, Mer, Jou" , respectively.
For examples, the number in Earth is called ' hel mar ' on Mars; and "Elo Nov" on the Mars corresponds to the Earth. In order to help communication between people from these-planets, you is supposed to write a program for mutual trans Lation between Earth and Mars number systems.

Input Specification:

Each input file contains the 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 the 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

Thinking of solving problems

String processing, carefully can

AC Code
#include <cstdio>#include <string>#include <cstring>#include <map>using namespace STD;Charstr1[ -][5] = {"Tret","Jan","the Feb","Mar","Apr","may","June","Jly"," the","Sep","Oct","Nov","Dec"};Charstr2[ -][5] = {"Tret","Tam","Hel","Maa","Huh","Tou","Kes","Hei","ELO","Syy","Lok","Mer","Jou"};intMain () { map<int, string>Iskv1, Iskv2; Map<string, int>Sikv1, Sikv2; for(inti =0; I <= A;        ++i) {Iskv1[i] = Str1[i];        Iskv2[i] = Str2[i];        Sikv1[str1[i]] = i;    Sikv2[str2[i]] = i; }intN, A;Chars[ +], s2[5];scanf("%d", &n); Gets (s); for(inti =0; I < n; ++i) {gets (s);if(s[0] >=' 0 '&& s[0] <=' 9 '){sscanf(S,"%d", &a);if(A > A) {if(a% -==0)printf("%s\n", iskv2[a/ -].c_str ());Else printf("%s%s\n", iskv2[a/ -].c_str (), iskv1[a% -].c_str ()); }Else{printf("%s\n", Iskv1[a].c_str ()); }        }Else{Char*p = Strtok (S," ");Char*P2 = Strtok (NULL," ");if(P && p2) {a = sikv2[p] * -;            A + = Sikv1[p2]; }Else if(p) {a = sikv2[p] * -;            A + = Sikv1[p]; }printf("%d\n", a); }    }return 0;}

1100. Mars Numbers (20) "String Processing"--pat (Advanced level) practise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.