HDOJ-1004 Let the Balloon Rise

简介: Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...

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 and find the result.

This year, they decide to leave this lovely job to you.

Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) – the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.

Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.

Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0
Sample Output
red
pink

统计出现次数最多的字符串然后输出,用冒泡的方法将相同字符串出现的次数统计到一个数组,然后记住出现次数最多位置,将这个位置的字符串输出。

//AC: 15MS  1692K
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    int N;
    while(scanf("%d",&N)!=EOF){
        char color[1005][20];
        int max=0,t=0,num[1005];
        if(N==0)
            break;
        for(int i=0;i<N;i++){
            scanf("%s",color[i]);
        }
        memset(num,0,sizeof(num));
        for(int i=1;i<N;i++)
            for(int j=0;j<i-1;j++)
                if(strcmp(color[i],color[j])==0)
                    num[i]++;
        for(int i=1;i<N;i++){
            if(max<num[i]){
                max=num[i];
                t=i;
            }
        }
        printf("%s\n",color[t]);
    }
    return 0;
}

开始还准备用map< string,int >来写,结果自己完全没理解map,满脑子骚操作。

目录
相关文章
|
弹性计算 自然语言处理 API
速成RAG+Agent框架大模型应用搭建
本文侧重于能力总结和实操搭建部分,从大模型应用的多个原子能力实现出发,到最终串联搭建一个RAG+Agent架构的大模型应用。
|
云安全 存储 运维
带你读《阿里云安全白皮书》(十七)——云上安全重要支柱(11)
阿里云提供了《阿里云安全白皮书(2024版)》,介绍客户数据安全保护技术能力。针对敏感行业,阿里云推出了专属区域和云盒两种形态,确保数据本地存储和合规要求,同时提供标准的公有云产品。此外,阿里云数据安全中心提供敏感数据识别、细粒度数据审计、数据脱敏/列加密、数据泄露检测与防护等四大功能,全面保障数据安全。
|
Rust 安全 Java
探索Rust语言的并发编程模型
探索Rust语言的并发编程模型
364 2
|
运维 测试技术
测试与开发问题之测试开发工程师与软件开发工程师和测试工程师如何区别
测试与开发问题之测试开发工程师与软件开发工程师和测试工程师如何区别
297 1
|
存储 网络安全 开发工具
Git 协同开发详解:从基础命令到多人协作
Git 协同开发详解:从基础命令到多人协作
345 0
|
机器学习/深度学习 数据采集 算法
机器学习赋能乳腺癌预测:如何使用贝叶斯分级进行精确诊断?
机器学习赋能乳腺癌预测:如何使用贝叶斯分级进行精确诊断?
381 0
|
数据可视化 前端开发
web前端-Echarts-5.3高级可视化和图表组合布局
web前端-Echarts-5.3高级可视化和图表组合布局
|
JSON 前端开发 Java
优化用户体验:SpringBoot统一异常处理最佳实践
优化用户体验:SpringBoot统一异常处理最佳实践
326 0
|
搜索推荐 小程序 Linux
分享88个搜索链接PHP源码,总有一款适合你
分享88个搜索链接PHP源码,总有一款适合你
713 0
N..
|
开发框架 Dart Android开发
Flutter概述
Flutter概述
N..
447 0