#include <iostream>
#include <string.h>
using namespace std;
const char str[][4] = {"yi","er","san","si","wu","liu","qi","ba","jiu"};
const int num[] = {2,2,3,2,2,3,2,2,3};//寻找对应的字符串的大小。
int GetIndex(char *s)
{
int i = 0;
for (;i<9;i++)
{
if (strncmp(str[i], s,strlen(str[i])) == 0)return i;
}
}
void Grial(char *str)
{
char *p = str;
char *s = new char[11];
int k = 0;
while (*p != ‘\0‘)
{
int index = GetIndex(p);
p += num[index];//跳过已经找到的这个数字。
s[k++] = index + ‘1‘;
s[k] = ‘\0‘;
}
cout << s << endl;//打印。
}
int main()
{
char *p = new char[100];
cin >> p;
Grial(p);
return 0;
}
时间: 2024-10-25 06:36:37