日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PAT 1100

發布時間:2023/11/29 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PAT 1100 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

解析:略 #include <iostream> #include <string> #include <cstring> #include <vector> #include <map> #include <stdio.h> using namespace std;string dict[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; string dict2[13] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};map<string, int> table; map<string, int> table2;void init(){for(int i=0; i<13; i++){table[dict[i]] = i;}for(int i=0; i<13; i++){table2[dict2[i]] = i;}return; }int pow(int n, int e){if(e == 0){return 1;}else{return n * pow(n, e-1);} }int mar2ear(string input){vector<string> tmp;int len = input.length();string str;for(int i=0; i<len; i++){if(input[i] != ' '){str.push_back(input[i]);if(i == len-1){tmp.push_back(str);str.clear();}}else{tmp.push_back(str);str.clear();}}int result = 0;for(int i=0; i<tmp.size(); i++){if(table[tmp[i]]){result += table[tmp[i]];}else{result += table2[tmp[i]] * 13;}}return result; }string ear2mar(int n){string result;int tmp1 = n/13;int tmp2 = n%13;if(tmp1 == 0){result = dict[tmp2];}else{result.append(dict2[tmp1]);if(tmp2 != 0){result.append(" ");result.append(dict[tmp2]);}}return result; }int toint(string input){int result = 0;int pos = 0;for(int i=input.length()-1; i>=0; i--){result += (input[i] - '0') * pow(10, pos);pos++;}return result; }int main(){init();int n;scanf("%d", &n);getchar();string line;while(n--){getline(cin, line);//is digitif(line[0] >= '0' && line[0] <= '9'){cout<<ear2mar(toint(line))<<endl;}else{cout<<mar2ear(line)<<endl;}}return 0; }

?

轉載于:https://www.cnblogs.com/RookieCoder/p/5075288.html

總結

以上是生活随笔為你收集整理的PAT 1100的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。