1295 爱翻译
1295 愛翻譯
題目描述
英語是現在世界第一大語言,所以學好英語是very important,
但是寧波大學的某個大牛說:“我不怕,我可以寫一個程序讓各種語言
快速轉換。”哎呀,學編程的,惹不起...溜...┈━═☆
咱不是大牛,但有追逐大牛的夢想,大牛的偉大程序不是隨便能盜版出來的,
我們就做一個簡單的翻譯器,把阿拉伯數字轉換為英文輸出。
輸入要求
小于10000的非負阿拉伯數字整數n。
輸出要求
對應的英文,如樣例,一個一行。
測試數據
//輸入
3923
5021
//輸出
three thousand nine hundred twenty three
five thousand twenty one
AC代碼
折磨人的代碼,多棒 = =
考慮好10-19,11是eleven,不是ten one
注意輸入0 也要輸出zero,而不是什么都不輸出
其他照舊
#include <bits/stdc++.h>
using namespace std;
int main() {
string in,res[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
string shi[10]={"","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
string shi2[10]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
int f,num;
while(cin>>in)
{
if(in.size()==1) //個位數單獨考慮
{
cout<<res[in[0]-'0']<<endl;continue;
}
f=0;
// 輸出千位和百位,如果沒有則不用輸出
for(int i=0;i<in.size()-2;i++)
{
if(in[i]=='0') continue;
if(f) cout<<" ";f=1;
cout<<res[in[i]-'0'];
if(in.size()-i==4) printf(" thousand");
if(in.size()-i==3) printf(" hundred");
}
// 輸出十位和個位
num=(in[in.size()-2]-'0')*10+in[in.size()-1]-'0';
if(num>=10 && num<=19)
{
if(f) cout<<" ";f=1;
cout<<shi2[num-10];
}
else
{
for(int i=in.size()-2;i<in.size();i++)
{
if(in[i]=='0') continue;
if(f) cout<<" ";f=1;
if(in.size()-i==2) cout<<shi[in[i]-'0'];
else cout<<res[in[i]-'0'];
}
}
cout<<endl;
}
return 0;
}
總結
- 上一篇: python中merge函数怎么用_Py
- 下一篇: HL7 RIM (转)