L1-007 念数字

该博客介绍了如何使用C++编程将输入的整数转换为其对应的中文拼音,特别是处理负数的情况。内容涵盖整数的拼音规则以及如何输出每个数字的拼音表示,输出结果之间以空格分隔。
摘要由CSDN通过智能技术生成

L1-007 念数字 (10分)

输入一个整数,输出每个数字对应的拼音。当整数为负数时,先输出fu字。十个数字对应的拼音如下:


0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu

输入格式:
输入在一行中给出一个整数,如:1234。

提示:整数包括负数、零和正数。

输出格式:
在一行中输出这个整数对应的拼音,每个数字的拼音之间用空格分开,行末没有最后的空格。如 yi er san si。

输入样例:

-600

输出样例:

fu liu ling ling
#include <iostream>
#include <string>
using namespace std;
int main()
{
     string string1;
     cin>>string1;
     for (int i=0; i<string1.length(); i++)
     {
          if(string1[i]=='0' && i==string1.length()-1)
          {
               cout<<"ling";
          }
          else if (string1[i]=='0')
          {
               cout<<"ling ";
          }
          if(string1[i]=='1' && i==string1.length()-1)
          {
               cout<<"yi";
          }
          else if (string1[i]=='1')
          {
               cout<<"yi ";
          }
          if(string1[i]=='2' && i==string1.length()-1)
          {
               cout<<"er";
          }
          else if (string1[i]=='2')
          {
               cout<<"er ";
          }
          if(string1[i]=='3' && i==string1.length()-1)
          {
               cout<<"san";
          }
          else if (string1[i]=='3')
          {
               cout<<"san ";
          }
          if(string1[i]=='4' && i==string1.length()-1)
          {
               cout<<"si";
          }
          else if (string1[i]=='4')
          {
               cout<<"si ";
          }
          if(string1[i]=='5' && i==string1.length()-1)
          {
               cout<<"wu";
          }
          else if (string1[i]=='5')
          {
               cout<<"wu ";
          }
          if(string1[i]=='6' && i==string1.length()-1)
          {
               cout<<"liu";
          }
          else if (string1[i]=='6')
          {
               cout<<"liu ";
          }
          if(string1[i]=='7' && i==string1.length()-1)
          {
               cout<<"qi";
          }
          else if (string1[i]=='7')
          {
               cout<<"qi ";
          }
          if(string1[i]=='8' && i==string1.length()-1)
          {
               cout<<"ba";
          }
          else if (string1[i]=='8')
          {
               cout<<"ba ";
          }
          if(string1[i]=='9' && i==string1.length()-1)
          {
               cout<<"jiu";
          }
          else if (string1[i]=='9')
          {
               cout<<"jiu ";
          }
          if(string1[i]=='-' && i==string1.length()-1)
          {
               cout<<"fu";
          }
          else if (string1[i]=='-')
          {
               cout<<"fu ";
          }
     }
     return 0;
    ********************************初学者代码繁琐望指教******************************
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值