【十二题解】 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include<stdio.h>
int f_min(int a, int b){
return a>b?b:a;
}
void prinf_ch(char*data, int start, int end){
int hash[26]={0};
int i, j;
int min=100;
for(i=start; i<=end; i++){
hash[data[i]-'a']++;
}
for(i=0; i<26; i++){
if(hash[i] != 0){
min=f_min(min, hash[i]);
}
}
for(i=start; i<=end; i++){
if(hash[data[i]-'a'] != min){
printf("%c", data[i]);
}
}
printf("\n");
}
int main(){
char charecter[1000]={0};
char*loc=charecter;
while(~scanf("%c", loc))loc++;
int lenth = (loc-charecter)/sizeof(char);
int i, j;
for(i=0; i<lenth; i=j+1){
for(j=i+1; charecter[j]!='\n'; j++){
if(charecter[j+1]=='\n'){//[i, j]就是字符串范围
prinf_ch(charecter, i, j);
}
}
}
return 0;
}