zoukankan      html  css  js  c++  java
  • acm_hdu Problem Archive 1004

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    int main()
    {
    int n = 0;
    while (scanf("%d",&n) != EOF && n!= 0)
    {
    char str[1000][16];//只对各不相同的颜色进行存储
    memset(str,0,sizeof(str));//all set to be NUL
    char tmp[16];
    int count[1000] = {0};//对应每个str[i]统计个数
    int len = 0;//str长度

    for (int i=0; i<n; i++)
    {
    scanf("%s",tmp);
    int tmplen = strlen(tmp);
    if (len == 0)//first color
    {
    strncpy(str[0],tmp,tmplen);
    len = 1;
    count[0] = 1;
    continue;
    }

    for (int i=0; i<len; i++)
    {
    if (strcmp(str[i],tmp) == 0)//str[i]和tmp同色,则对应count[i]++
    {
    count[i]++;
    break;
    }

    if (i == len-1)//之前所有的str[i]和tmp都不同色,添加新色str[len]
    {
    strncpy(str[len],tmp,tmplen);
    count[len] = 1;
    len++;
    break;//注意此处要break,否则最后一次匹配len++,会导致for额外循环一次!
    }
    }
    }

    int max = count[0];
    int pos = 0;
    for (int i=0; i<len; i++)
    {
    //printf("%s:%d ", str[i],count[i]);
    if (count[i] > max)
    {
    max = count[i];
    pos = i;
    }
    }
    printf("%s ",str[pos]);
    }
    return 0;
    }

  • 相关阅读:
    [HAOI2006] 数字序列
    [HAOI2012] 外星人
    [HAOI2012] 高速公路
    [HAOI2007] 覆盖问题
    [HAOI2007] 分割矩阵
    [HAOI2007] 上升序列
    牛客练习赛58 D 迷宫
    牛客练习赛58 F XOR TREE
    牛客练习赛58 E 最大GCD
    牛客练习赛58 C 矩阵消除游戏
  • 原文地址:https://www.cnblogs.com/kimihe/p/4509968.html
Copyright © 2011-2022 走看看