题目:
输入一个整数,输出每个数字对应的拼音。当整数为负数时,先输出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.h>
#include<map>
using namespace std;
int main()
{
char a[1000];
fgets(a, 1000, stdin);
int x = strlen(a);
map<char, string>mymap{{'-',"fu"},{'0',"ling"},{'1',"yi"}, {'2',"er"}, {'3',"san"}, {'4',"si"}, {'5',"wu"}, {'6',"liu"}, {'7',"qi"}, {'8',"ba"}, {'9',"jiu"}, };
cout<<mymap[a[0]];
for (int i = 1; i < x-1; i++)
{
cout <<" "<< mymap[a[i]];
}
if(a[x-1]=='0')cout<<" ling";
if(a[x-1]=='1')cout<<" yi";
if(a[x-1]=='2')cout<<" er";
if(a[x-1]=='3')cout<<" san";
if(a[x-1]=='4')cout<<" si";
if(a[x-1]=='5')cout<<" wu";
if(a[x-1]=='6')cout<<" liu";
if(a[x-1]=='7')cout<<" qi";
if(a[x-1]=='8')cout<<" ba";
if(a[x-1]=='9')cout<<" jiu";
return 0;
}
```c++
#include<iostream>
#include<string.h>
#include<map>
using namespace std;
int main()
{
char a[1000];
fgets(a, 1000, stdin);
int x = strlen(a);
map<char, string>mymap{{'-',"fu"},{'0',"ling"},{'1',"yi"}, {'2',"er"}, {'3',"san"}, {'4',"si"}, {'5',"wu"}, {'6',"liu"}, {'7',"qi"}, {'8',"ba"}, {'9',"jiu"}, };
cout<<mymap[a[0]];
for (int i = 1; i < x; i++)
{
cout <<" "<< mymap[a[i]];
}
return 0;
}
```