标题:c++输入整数输出对应中文
只看楼主
莫启飞
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2021-10-13
结帖率:100%
已结贴  问题点数:20 回复次数:5 
c++输入整数输出对应中文
预期结果:请帮忙解一下这题,如果能附加注释是最好的了,谢谢,新手上路
Problem Description
给出在[0, 100]范围内的整数数字,你能把对应的中文写出来吗?
Input
第一行输入一个T (T <= 20),后面每行一个数字,题目保证数字是[0, 100]。
Output
第一行输入一个T (T <= 20),后面每行一个数字,题目保证数字是[0, 100]。
Sample Input
5
1
22
3
4
100
Sample Output

二十二


一百
搜索更多相关主题的帖子: c++ 输入 整数 中文 对应 
2021-10-15 22:55
apull
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:三体星系
等 级:版主
威 望:185
帖 子:1404
专家分:8479
注 册:2010-3-16
得分:20 
程序代码:
#include <iostream>
using namespace std;

int main()
{
    string strH[] = {"", "", "", "", "", "", "", "", ""};
    string str[20] = {""}; //保存各组结果
    int T;
    cin >> T; //输入组数
    if (T > 20)
        return 1;
    
    int tmp, g, s;

    for (int i = 0; i < T; i++)
    {
        cin >> tmp; //输入各组数字
        if (tmp == 0)
            str[i] = string("");
        else if (tmp == 100)
            str[i] = string("一百");
        else
        {
            g = tmp % 10;
            s = tmp / 10;
            //拼接字符串
            if (s > 0)
            {
                str[i] = strH[s - 1] + "";
                if (g > 0)
                    str[i] +=  strH[g - 1];
            }
            else
                str[i] = strH[g - 1];
        }
    }

    for (int i = 0; i < T; i++)
    {
        cout << str[i] << endl;
    }

 
    return 0;
}



[此贴子已经被作者于2021-10-16 01:04编辑过]

2021-10-16 00:53
莫启飞
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2021-10-13
得分:0 
回复 2楼 apull
您好您能再帮我看一下吗,我拿您的代码去OJ上提交显示的是 Wrong Answer 错误, 谢谢您了
2021-10-16 20:50
apull
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:三体星系
等 级:版主
威 望:185
帖 子:1404
专家分:8479
注 册:2010-3-16
得分:0 
估计是“十”成了“一十”
2021-10-16 21:34
莫启飞
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2021-10-13
得分:0 
你好,我拿您给的代码去oj上提交时显示下面的内容,我实在再不懂,您能看看吗,谢谢
2_37884_3662168_495.cpp
2_37884_3662168_495.cpp(40) : error C2679: 二进制“<<”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)
        2013\INCLUDE\ostream(498): 可能是“std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::basic_streambuf<char,std::char_traits<char>> *)”
        2013\INCLUDE\ostream(478): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(const void *)”
        2013\INCLUDE\ostream(458): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(long double)”
        2013\INCLUDE\ostream(438): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(double)”
        2013\INCLUDE\ostream(418): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(float)”
        2013\INCLUDE\ostream(397): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(unsigned __int64)”
        2013\INCLUDE\ostream(377): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(__int64)”
        2013\INCLUDE\ostream(356): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(unsigned long)”
        2013\INCLUDE\ostream(336): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(long)”
        2013\INCLUDE\ostream(316): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(unsigned int)”
        2013\INCLUDE\ostream(291): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(int)”
        2013\INCLUDE\ostream(271): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(unsigned short)”
        2013\INCLUDE\ostream(237): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(short)”
        2013\INCLUDE\ostream(217): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::_Bool)”
        2013\INCLUDE\ostream(210): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))”
        2013\INCLUDE\ostream(203): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::basic_ios<char,std::char_traits<char>> &(__cdecl *)(std::basic_ios<char,std::char_traits<char>> &))”
        2013\INCLUDE\ostream(197): 或       “std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::basic_ostream<char,std::char_traits<char>> &(__cdecl *)(std::basic_ostream<char,std::char_traits<char>> &))”
        2013\INCLUDE\ostream(1026): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,const std::error_code &)”
        2013\INCLUDE\ostream(988): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<char,std::char_traits<char>,std::string>(std::basic_ostream<char,std::char_traits<char>> &&,const _Ty &)”
        with
        [
            _Ty=std::string
        ]
        2013\INCLUDE\ostream(978): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,unsigned char)”
        2013\INCLUDE\ostream(971): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,const unsigned char *)”
        2013\INCLUDE\ostream(964): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,signed char)”
        2013\INCLUDE\ostream(957): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,const signed char *)”
        2013\INCLUDE\ostream(831): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char)”
        2013\INCLUDE\ostream(784): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,const char *)”
        2013\INCLUDE\ostream(746): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char)”
        2013\INCLUDE\ostream(699): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,const char *)”
        尝试匹配参数列表“(std::ostream, std::string)”时
2021-10-16 23:45
apull
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:三体星系
等 级:版主
威 望:185
帖 子:1404
专家分:8479
注 册:2010-3-16
得分:0 
加一句 #include <string> 看看。

http://www.
2021-10-17 00:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-507174-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.613976 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved