CODEFORCES 535A 解题报告

CODEFORCES 535A 解题报告

本题仍为水题,只要按照英语中的数字命名法来就可以了,STL简化一下操作,把基本元素枚举出来就可以了。map1~10,20,30,…,90。映射为单词。之后拆分十位和个位,用连字符拼接即可。
以下是代码(可直接AC):

#include <iostream>
#include <string>
#include <map>

using std::cin;
using std::cout;
using std::map;
using std::string;

int main()
{
    int s;
    map<int,string> word;
    //直接枚举
    word[0]="zero"; 
    word[1]="one"; 
    word[2]="two"; 
    word[3]="three"; 
    word[4]="four";
    word[5]="five"; 
    word[6]="six"; 
    word[7]="seven"; 
    word[8]="eight"; 
    word[9]="nine";
    word[10]="ten";
    word[11]="eleven"; 
    word[12]="twelve"; 
    word[13]="thirteen"; 
    word[14]="fourteen";
    word[15]="fifteen"; 
    word[16]="sixteen"; 
    word[17]="seventeen"; 
    word[18]="eighteen"; 
    word[19]="nineteen";
    word[20]="twenty"; 
    word[30]="thirty"; 
    word[40]="forty"; 
    word[50]="fifty"; 
    word[60]="sixty"; 
    word[70]="seventy"; 
    word[80]="eighty"; 
    word[90]="ninety";
    cin>>s;
    if(s>=0&&s<=19||s%10==0)//0~9不拆,整十不拆
        cout<<word[s];
    else
        cout<<word[s-s%10]<<'-'<<word[s%10];//拆分输出
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值