思路
- 有些字母对于数字英文是唯一的,
- 筛选第一遍后,有些字母对于数字英文是唯一的
- 筛选第二遍后,有些字母对于数字英文是唯一的
int cmp(const void* a,const void *b) {
int c = *(int *)a;
int d = *(int *)b;
return c - d;
}
char * originalDigits(char * s){
int count[256] = {0};
int i;
int res[15000] = {0};
char *ress = (char*)malloc(sizeof(char) * 15000);
int len = strlen(s);
for (i = 0; i < len; i++) {
count[s[i]] ++;
}
int rescount=0;
while(count['z']--){
res[rescount++] = 0;
count['e']--;
count['r']--;
count['o']--;
}
while(count['w']--){
res[rescount++] = 2;
count['t']--;
count['o']--;
}
while(count['u']--){
res[rescount++] = 4;
count['o']--;
count['r']--;
count['f']--;
}
while(count['x']--){
res[rescount++] = 6;
count['i']--;
count['s']--;
}
while(count['g']--){
res[rescount++] = 8;
count['e']--;
count['i']--;
count['h']--;
count['t']--;
}
while(count['o']--){
res[rescount++] = 1;
count['e']--;
count['n']--;
}
while(count['f']--){
res[rescount++] = 5;
count['e']--;
count['i']--;
count['v']--;
}
while(count['h']--){
res[rescount++] = 3;
count['e']--;
count['e']--;
count['t']--;
count['r']--;
}
while(count['i']--){
res[rescount++] = 9;
}
while(count['v']--){
res[rescount++] = 7;
}
qsort(res, rescount, sizeof(int), cmp);
for (i = 0; i < rescount; i++) {
ress[i] = res[i] + '0';
}
ress[rescount] = '\0';
return ress;
}