千の悲しい理由の[シミュレーション]愛と悲しみ

オリジナルタイトルポータル

考え


この質問は、私は本当に無力Tucao、しかし、この質問は本当に良いQAQ対象です。

この質問は難しいことではありませんが、それは忍耐と慎重のテストで注意しないが、私は60ポイントを持っていたコードの先頭を見つけることができません場合は、小さなミスの様々ながある、いくつかの例を見落とすことで、その後、繰り返しテストデータのみAC QAQ(たぶん私はあまりにも弱いんだという理由だけで)

これは、ブラシの価値があります

コード


#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
using namespace std;

int n;
int s[5];
string a[25]={"","one","two","three",
"four","five","six","seven","eight","nine",
"ten","eleven","twelve","thirteen","fourteen",
"fifteen","sixteen","seventeen","eighteen","nineteen"};
string x[20]={"","","twenty","thirty","forty","fifty",
"sixty","seventy","eighty","ninety"};
int main()
{
    cin>>n;
    int i=4;
    while(n!=0)
    {
        s[i]=n%10;
        n/=10;
        i--;
    }
    if(s[1]!=0)
        cout<<a[s[1]]<<" thousand ";
    if(s[2]!=0)
        cout<<a[s[2]]<<" hundred "; 
    else if(s[3]!=0&&s[4]!=0&&(s[2]!=0||s[1]!=0))
        cout<<"and ";       
    if(s[3]==0&&s[4]!=0&&(s[2]!=0||s[1]!=0))
        cout<<"and "<<a[s[4]]<<endl;
    else if(s[3]==0&&s[4]!=0)
        cout<<a[s[4]]<<endl;
    else if(s[3]==1)
        cout<<a[s[4]+10]<<endl;
    else if(s[4]!=0)
        cout<<x[s[3]]<<" "<<a[s[4]];
    if(s[1]==0&&s[2]==0&&s[3]==0&&s[4]==0)
        cout<<"zero";
    return 0;
}

おすすめ

転載: www.cnblogs.com/gongdakai/p/11622757.html