拼写检查
#include <stdio.h>
#include <string.h>
int hash[255];
void init()
{
hash['B'] = hash['F'] = hash['P'] = hash['V'] = 1;
hash['C'] = hash['G'] = hash['J'] = hash['K'] = 2;
hash['Q'] = hash['S'] = hash['X'] = hash['Z'] = 2;
hash['D'] = hash['T'] = 3;
hash['L'] = 4;
hash['M'] = hash['N'] = 5;
hash['R'] = 6;
}
int main()
{
init();
int ans[25], top;
char data[25];
while(gets(data))
{
top = 1;
int l = strlen(data);
for(int i = 0; i < l; i++)
{
int t = hash[data[i]];
if(t == ans[top - 1]) continue;
ans[top++] = t;
}
for(int i = 1; i < top; i++)
{
if(ans[i]) printf("%d", ans[i]);
}
printf("\n");
}
return 0;
}