HDOJ 1004(字符串分类统计)

#include<stdio.h>
#include<string.h>
typedef struct//二维数组没有这个方便
{
    char str[16];
    int num;
}Node;
int main()
{
    Node col[1001];
    int T,i,j,max;
    while(~scanf("%d",&T),T)
    {
        getchar();
        for(i=1;i<=T;i++)
            col[i].num=0;
        for(i=1;i<=T;i++)
        {
            scanf("%s",col[i].str);
            getchar();
            for(j=1;j<=i;j++)
                if(strcmp(col[j].str,col[i].str)==0)
                col[i].num++;
        }
        max=0;
        j=1;
        for(i=1;i<=T;i++)
        {
            if(col[i].num>max)
            {
                max=col[i].num;
                j=i;
            }
        }
        printf("%s\n",col[j].str);
    }
}
时间: 2024-09-20 08:10:12

HDOJ 1004(字符串分类统计)的相关文章

HDOJ 1004 Let the Balloon Rise

Problem Description Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color

HDOJ 2017 字符串统计

Problem Description 对于给定的一个字符串,统计其中数字字符出现的次数. Input 输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串. Output 对于每个测试实例,输出该串中数值的个数,每个输出占一行. Sample Input 2 asdfasdf123123asdfasdf asdf111111111asdfasdfasdf Sample Output 6 9 需要注意的只有一个地方,就是输入数字后回车的处理.

HDOJ 1004题 Let the Balloon Rise strcmp()函数

Problem Description Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color

HDOJ 1004

#include<stdio.h> #include<string.h> typedef struct//二维数组没有这个方便 { char str[16]; int num; }Node; int main() { Node col[1001]; int T,i,j,max; while(~scanf("%d",&T),T) { getchar(); for(i=1;i<=T;i++) col[i].num=0; for(i=1;i<=T;

C++实现分类统计字符串中字符个数

#include <iostream> using namespace std; int main(int argc, char **argv) { int a,b,c,d,e,len; string str; cout<<"请输入一个字符串:"; getline(cin,str); len=str.length(); a=b=c=d=e=0; for (int i = 0; i < len; i++) { char ch=str[i]; cout<

HDOJ/HDU 1073 Online Judge(字符串处理~)

Problem Description Ignatius is building an Online Judge, now he has worked out all the problems except the Judge System. The system has to read data from correct output file and user's result file, then the system compare the two files. If the two f

HDOJ/HDU 1088 Write a simple HTML Browser(HTML字符串)

Problem Description If you ever tried to read a html document on a Macintosh, you know how hard it is if no Netscape is installed. Now, who can forget to install a HTML browser? This is very easy because most of the times you don't need one on a MAC

HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)

Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book

HDOJ/HDU 1200 To and Fro(加密解密字符串)

Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array