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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

PAT甲级题解-1100. Mars Numbers (20)-字符串处理

發布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PAT甲级题解-1100. Mars Numbers (20)-字符串处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  沒什么好說的,注意字符串的處理,以及當數字是13的倍數時,只需高位叫法的單詞。比如26,是“hel”,而不是“hel tret”。

代碼:

#include <iostream> #include <cstdio> #include <algorithm> #include <map> #include <string> #include <string.h> using namespace std; char mars1[13][20]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; char mars2[13][20]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; map<char*,int>maps;int main() {int n;char str[20];int decade,digit;scanf("%d",&n);getchar();for(int i=0;i<n;i++){gets(str);if('0'<=str[0]&&str[0]<='9'){int num=atoi(str);if(num/13 && num%13==0){//注意整除的情況。。。printf("%s\n",mars2[num/13]);}else if(num/13){decade=num/13;digit=num%13;printf("%s %s\n",mars2[decade],mars1[digit]);}else{printf("%s\n",mars1[num]);}}else{int len=strlen(str);//如果是一個字符串的話,加上\0頂多4位。不過要注意也要比較下十位數if(len<5){digit=-1;for(int i=0;i<13;i++){if(strcmp(str,mars1[i])==0){digit=i;break;}}if(digit==-1){for(int i=1;i<13;i++){if(strcmp(str,mars2[i])==0){decade=i;break;}}printf("%d\n",decade*13);}elseprintf("%d\n",digit);}else{char tmp[20];int i;for(i=0;i<len && str[i]!=' ';i++){tmp[i]=str[i];}tmp[i]='\0';//十位數for(int k=1;k<13;k++){if(strcmp(tmp,mars2[k])==0){decade=k;break;}}i++;int p=0;for(;i<len;i++,p++)tmp[p]=str[i];tmp[p]='\0';//個位數for(int k=0;k<13;k++){if(strcmp(tmp,mars1[k])==0){digit=k;break;}}printf("%d\n",decade*13+digit);}}}return 0; } View Code

?

轉載于:https://www.cnblogs.com/chenxiwenruo/p/6102581.html

總結

以上是生活随笔為你收集整理的PAT甲级题解-1100. Mars Numbers (20)-字符串处理的全部內容,希望文章能夠幫你解決所遇到的問題。

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