标签:style blog color for io div
//输入数字的汉语拼音,每个拼音的首字母大写。输出该数字的阿拉伯数字。
//JiuBaiJiuShiJiu -> 999
#include<stdio.h>
#include<string.h>
int result = 0;
void add(int n,char wei[])
{
if(strcmp(wei,"Wan") == 0)
result = result + n * 10000;
else if(strcmp(wei,"Qian") == 0)
result = result + n * 1000;
else if(strcmp(wei,"Bai") == 0)
result = result + n * 100;
else if(strcmp(wei,"Shi") == 0)
result = result + n * 10;
else
result = result + n;
}
int main()
{
char s[255];
int i,n;
int row=0,column;
char pinyin[10][10] = {"Ling","Yi","Er","San","Si","Wu","Liu","Qi","Ba","Jiu"};//pinyin[n]为n的拼音。
char data[100][100];//将输入的字符串分隔,存储在data里
gets(s);
//将读入的字符串,放到data数组中。每行放一个拼音。
for(i=0;s[i]!=‘\0‘;)
{
if(s[i] >= ‘A‘ && s[i] <= ‘Z‘)
{
column = 0;
do
{
data[row][column++] = s[i++];
}
while(s[i] >= ‘a‘ && s[i] <= ‘z‘);
data[row++][column] = ‘\0‘;
}
}
//遍历data[][]里的所有行,计算结果
for(i=0;i<row;i++)
{
for(n=1;n<=9;n++)
{
//如果当前行data[i]为1-9的拼音的话,下一行data[i+1]即为该拼音的权值。
if(strcmp(data[i],pinyin[n]) == 0)
{
i++;
add(n,data[i]);
}
}
}
printf("%d",result);
return 0;
}
[华为机试]输入数字的汉语拼音,每个拼音的首字母大写。输出该数字的阿拉伯数字。,布布扣,bubuko.com
[华为机试]输入数字的汉语拼音,每个拼音的首字母大写。输出该数字的阿拉伯数字。
标签:style blog color for io div
原文地址:http://www.cnblogs.com/Camilo/p/3830480.html