报时助手——蓝桥杯基础练习

我之所以写这个博客,因为关于字符串存储的问题

题目的描述是这样的

这道题的思路还是比较简单的,把这些情况全部定义成一个数组,来保存字符串,下面是我的代码:

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>

using namespace std;

string lookfor[]={"zero","one","two","three","four","five","six","seven",
"eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen",
"sixteen","seventeen","eighteen","nineteen","twenty","thirty","forty","fifty"};
int h,m;
string r="o'clock";//在这里我定义了一个未知数量的字符串数组特别重要!!!!!!

void lookfortime(int n)//不管是小时还是分钟都要通过这个函数来输出
{
    int a,b;
    a=n/10;
    b=n%10;
    if(n<=20)
    {
        cout<<lookfor[n];
    }
    else
    {
        cout<<lookfor[a+18];
        if(b!=0)
        {
            cout<<' '<<lookfor[b];
        }
    }
}

void output()
{
    if(m==0)
    {
        lookfortime(h);
        cout<<' ' << r;
    }
    else
    {
        lookfortime(h);
        cout<<' ';
        lookfortime(m);
    }
}
int main()
{
    cin>>h>>m;
    output();
    return 0;
}

那个字符串存储原理:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值