标签:字符串
#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;
}
标签:字符串
原文地址:http://blog.csdn.net/liuhuiyan_2014/article/details/46559543