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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

PAT-Mars number

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

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



本題題意就是在題目描述的火星數字規則下與阿拉伯數字的轉換 輸入一個阿拉伯數字 輸出一個對應的火星文 輸入一個火星文 輸出一個對應的地球數字


本題需要注意的是 雖然沒在題目中描述出來 但可以從樣例中看到 當數字是13的整數倍時 不需要輸出0----tret 只需要輸出前面的取整的大數部分

如輸入13時 只需要輸出tam 不需要輸出后面的0 其余情況就是13與10進制的轉換問題了 通過查表和進制轉換輸出結果

本題在數據轉換的時候可以利用stringstream

將string類型轉化為int:

?stringstream s;

?string a;

?cin>>string;

?s<<a;

?int t;

?s>>t;

頭文件:#include<sstream>

后來一直最后兩個數據過不了 。。。查了好久后發現原來是low數組中的數據抄重了一個。。。- -初始化很重要!!!

#include<cstdio> #include<stack> #include<cmath> #include<sstream> #include<cstring> #include<iostream> using namespace std; int main() {int n;//0-24string low[]={ "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"};cin>>n; getchar();while(n--){string a;getline(cin,a);if(isdigit(a[0])){stringstream s;s<<a;int t=0;s>>t;s.clear();string res;if(t<13)res.append(low[t]);else if(t%13==0)res.append(low[t/13+12]);else{stack<int>s;while(t){s.push(t%13);t/=13; } int d=s.top();s.pop();res.append(low[d+12]);res.append(" ");d=s.top();res.append(low[d]);} cout<<res<<endl;}else{ int res=0;int pos=a.find(" ");if(pos!=-1)for(int i=0;i<=24;i++){int lpos=a.find(low[i]);if(lpos!=-1&&lpos<pos){res+=(i-12)*13;// cout<<(i-12)*13<<endl;}else if(lpos!=-1){res+=i;// cout<<i<<endl;}} else for(int i=0;i<25;i++)if(a.find(low[i])!=-1&&i<13)res+=i;else if(a.find(low[i])!=-1)res+=(i-12)*13;cout<<res<<endl;}}return 0; }







總結

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

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