原題鏈接:PAT (Basic Level) Practice (中文)1044 火星數(shù)字
做前思考
1外构、字符串輸入瘸爽,當(dāng)讀入地球數(shù)字時,比較簡單的進(jìn)制轉(zhuǎn)換。當(dāng)讀入火星數(shù)字時精刷,分兩類拗胜,即:一串與兩串,再進(jìn)行進(jìn)制轉(zhuǎn)換贬养。
2挤土、我用一個字符判斷火星數(shù)字類型。
做后總結(jié)
1误算、代碼長仰美,但無腦。儿礼。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char a[8],ch;
char *ri[]={"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
char *yue[] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int n,i,j,shi,ge,x,flag,con;
scanf("%d",&n);
for(i=0;i<n;i++)
{
flag=0;
x=0;
con=0;
scanf("%s",a);
ch=getchar();
if(ch==' ')
{
flag=1;
}
if(a[0]>='0'&&a[0]<='9')
{
x=atoi(a);
if(x==0)
{
printf("%s\n",ri[0]);
}else{
shi=x/13;
ge=x%13;
if(ge==0)
{
printf("%s\n",yue[shi-1]);
}else if(shi==0)
{
printf("%s\n",ri[ge]);
}else{
printf("%s %s\n",yue[shi-1],ri[ge]);
}
}
}else{
if(flag==0)
{
for(j=0;j<12;j++)
{
if(strcmp(a,yue[j])==0)
{
x=(j+1)*13;
con=1;
}
}
if(con==0)
{
for(j=0;j<13;j++)
{
if(strcmp(a,ri[j])==0)
{
x=j;
}
}
}
printf("%d\n",x);
}else{
for(j=0;j<12;j++)
{
if(strcmp(a,yue[j])==0)
{
x=(j+1)*13;
}
}
scanf("%s",a);
for(j=0;j<13;j++)
{
if(strcmp(a,ri[j])==0)
{
x+=j;
}
}
printf("%d\n",x);
}
}
}
return 0;
}