Chinaunix首页 | 论坛 | 博客
  • 博客访问: 71806
  • 博文数量: 41
  • 博客积分: 1475
  • 博客等级: 上尉
  • 技术积分: 440
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-27 22:49
文章分类
文章存档

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;
}

阅读(349) | 评论(0) | 转发(0) |
0

上一篇:ACM UVA (10007)

下一篇:ACM UVA (403)

给主人留下些什么吧!~~