戏雷chnos.blog.chinaunix.net
chnos
全部博文(41)
ACM UVA题(38)
2012年(8)
2011年(1)
2009年(32)
止觞
分类:
2009-04-16 20:22:30
/* ******************************************************************************* * * Filename: 499.c * * Description: * * Version: 0.1 * Created: 4/13/2009 12:30:02 PM * * Author: Ye Xiaofeng , yexf # gmail.com * ******************************************************************************* */ #include <stdio.h> #include <stdlib.h> #include <string.h> int compare(const void *v1, const void *v2); int main(int argc, char **argv) { char line_buffer[1024]; char *ptr = NULL; char result[52]; int result_num = 0; int max_freq = 0; int cur_freq = 0; int i = 0; char cur_char = 0; int len = 0; ptr = gets(line_buffer); while (NULL != ptr) { len = strlen(line_buffer); qsort(line_buffer, len, 1, compare); cur_char = 0; cur_freq = 0; cur_char = 0; result_num = 0; max_freq = 0; for (i = 0; i < len+1; i++) { if (!isalpha(line_buffer[i]) && line_buffer[i] != '\0') { continue; } if (line_buffer[i] != cur_char) { if (max_freq < cur_freq) { result_num = 0; result[result_num] = cur_char; max_freq = cur_freq; result_num++; } else if (max_freq == cur_freq) { result[result_num] = cur_char; result_num++; } cur_char = line_buffer[i]; cur_freq = 1; } else { cur_freq++; } } for (i = 0; i < result_num; i++) { printf("%c", result[i]); } printf(" %d\n", max_freq); ptr = gets(line_buffer); } } int compare(const void *v1, const void *v2) { return *(char*)v1 - *(char*)v2; }
上一篇:ACM UVA (10007)
下一篇:ACM UVA (403)
登录 注册