码迷,mamicode.com
首页 > 其他好文 > 详细

【模拟】爱与愁的一千个伤心的理由

时间:2019-10-04 19:12:22      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:namespace   数据   lan   class   www   吐槽   http   cst   cout   

原题传送门

思路


这道题的题目我是真的无力吐槽,但是,这道题真心不错QAQ。

这道题不难,但很考验耐心与细心,有各种各样的小错误,如果不细心都不会发现,我最开始的代码只得了60分,就是忽略了好几个情况,然后反复测试数据,才AC的QAQ(也许只是因为我太弱了)

值得一刷

Code


#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;
}

【模拟】爱与愁的一千个伤心的理由

标签:namespace   数据   lan   class   www   吐槽   http   cst   cout   

原文地址:https://www.cnblogs.com/gongdakai/p/11622757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!