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;
********************************初学者代码繁琐望指教******************************
}