标签:div 编写 else ble 编写程序 实现 strlen n+1 getc
https://pintia.cn/problem-sets/994805260223102976/problems/994805279328157696
火星人是以13进制计数的:
例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字“115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。
输入格式:
输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 —— 或者是地球文,或者是火星文。
输出格式:
对应输入的每一行,在一行中输出翻译后的另一种语言的数字。
输入样例:
4
29
5
elo nov
tam
输出样例:
hel mar
may
115
13
#include <bits/stdc++.h>
using namespace std;
int cmpchar(const char* a,const char* b)
{
int lena=strlen(a);
int lenb=strlen(b);
if(lena!=lenb)
return 0;
else
{
for(int i=0; i<lena; i++)
{
if(a[i]!=b[i])
return 0;
}
}
return 1;
}
char s[10],c[5];
//第一个出来对应 ge
char ge[15][15]= {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
//第二个出来对应 shi
char shi[15][15]= {"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
char a[15][15];
int main()
{
int T;
scanf("%d",&T);
getchar();
for(int i=1; i<=T; i++)
{
cin.getline(s,10);
int len=strlen(s);
int num=0;
int ans=0,sum1=0;
int flag=0;
if(s[0]>=‘0‘&&s[0]<=‘9‘)
{
for(int i=0; i<len; i++)
num=num*10+s[i]-‘0‘;
if(num<13)
cout<<ge[num]<<endl;
else if(num%13==0)
{
cout<<shi[num/13]<<endl;
}
else
{
cout<<shi[num/13%13]<<" "<<ge[num%13]<<endl;
}
}
else
{
s[len]=‘ ‘;
s[len+1]=‘\0‘;
for(int i=0; i<len+1; i++)
{
if(s[i]!=‘ ‘)
for(int j=i; j<len+1; j++)
{
if(s[j]!=‘ ‘)
continue;
else
{
ans++;
for(int k=i; k<j; k++)
{
a[ans][k-i]=s[k];
}
a[ans][j-i]=‘\0‘;
i=j;
break;
}
}
}
for(int i=0; i<=14; i++)
{
if(ans==1)
{
if(cmpchar(a[1],ge[i])==1)
cout<<i<<endl;
else if(cmpchar(a[1],shi[i])==1)
cout<<13*i<<endl;
}
else if(ans==2)
{
flag=1;
if(cmpchar(a[1],shi[i])==1)
sum1+=13*i;
if(cmpchar(a[2],ge[i])==1)
sum1+=i;
// cout<<sum1<<endl;
}
}
if(flag==1)
cout<<sum1<<endl;
}
}
return 0;
}
标签:div 编写 else ble 编写程序 实现 strlen n+1 getc
原文地址:https://www.cnblogs.com/zlrrrr/p/9339623.html