【PAT甲级】1100 Mars Numbers (20 分)
题意:
输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字。
AAAAAccepted code:
1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 char a[20][20]={"0","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"}; 5 char b[20][20]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"}; 6 int main(){ 7 ios::sync_with_stdio(false); 8 cin.tie(NULL); 9 cout.tie(NULL); 10 int n; 11 cin>>n; 12 cin.ignore(); 13 for(int q=1;q<=n;++q){ 14 string s; 15 getline(cin,s); 16 if(s[0]>='0'&&s[0]<='9'){ 17 int temp=0; 18 for(int j=0;j<s.size();++j){ 19 temp*=10; 20 temp+=s[j]-'0'; 21 } 22 int x=temp/13; 23 int y=temp%13; 24 if(x&&y) 25 cout<<a[x]<<" "<<b[y]<<"\n"; 26 else if(x) 27 cout<<a[x]<<"\n"; 28 else 29 cout<<b[y]<<"\n"; 30 } 31 else{ 32 if(s[3]==' '&&s[4]!=0){ 33 char x[4]={},y[4]={}; 34 for(int i=0;i<3;++i) 35 x[i]=s[i]; 36 for(int i=4;i<7;++i) 37 y[i-4]=s[i]; 38 int pos=0; 39 for(int i=1;i<=12;++i){ 40 if(strcmp(a[i],x)==0){ 41 pos=i; 42 break; 43 } 44 } 45 int pos2=0; 46 for(int i=1;i<=12;++i){ 47 if(strcmp(b[i],y)==0){ 48 pos2=i; 49 break; 50 } 51 } 52 int temp=pos*13+pos2; 53 cout<<temp<<"\n"; 54 } 55 else if(s[4]!=0&&s[5]==0) 56 cout<<"0\n"; 57 else{ 58 char x[4]={}; 59 for(int i=0;i<3;++i) 60 x[i]=s[i]; 61 int pos=0; 62 for(int i=1;i<=12;++i) 63 if(strcmp(a[i],x)==0){ 64 pos=i; 65 break; 66 } 67 int pos2=0; 68 for(int i=1;i<=12;++i) 69 if(strcmp(b[i],x)==0){ 70 pos2=i; 71 break; 72 } 73 int temp=pos*13+pos2; 74 cout<<temp<<"\n"; 75 } 76 } 77 } 78 return 0; 79 }
保持热爱 不懈努力
不试试看怎么知道会失败呢(划掉)
世上无难事 只要肯放弃(划掉)