zoukankan      html  css  js  c++  java
  • Let the Balloon Rise

    先看看题目

    这题让我崩溃了两小时,提交了10次才对,说明能力太渣了,得加油,加油!

    本题我的迷糊点:1、题目的输出是一次实例一个输出,我刚开始将他一起输出,提交了好多次,后来运行了网上的结果,才知道,题目理解错了。

    本题题目是:先输入一个n,紧接着n输入n个颜色,然后将输出颜色最多的那种颜色,注意如果有颜色一样的,输出排在前面的颜色

    本题代码:

    #include<iostream>
    #include<map>
    #include<string>
    using namespace std;


    int main()
    {

    map<string ,int>mapint;//定义map存放颜色统计
    while(true)
    {
    map<string ,int>mapint;//定义map存放颜色统计
    int count=0;//测试用例个数
    cin>>count;
    if(count>0&&count<=1000)
    {
    string colors;
    for(int i=0;i<count;i++)
    {
    cin>>colors;
    if(mapint.find(colors)==mapint.end())//查到最后也没发现,那就添加
    {
    mapint.insert(map<string ,int>::value_type(colors,1));
    }
    else//存在,那么数量增加1
    {
    mapint[colors] =mapint[colors]+1;
    }
    }
    int cc=0;string color;
    for( std::map<string, int>::iterator iter = mapint.begin();iter != mapint.end(); ++ iter )
    {
    if(cc<iter->second)
    {
    cc=iter->second;
    color=iter->first;
    }
    }
    cout << color <<endl;

    }
    else if(count==0)//退出
    {
    break;
    }
    }
    return 0;
    }

    本代码中我使用了map,主要是我觉得可以动态往里面加键值对,而不是像数组那样需要定义固定大小的数组

    但是map如何使用呢,我因为初学c++也不是太清楚,所以参照了网页http://blog.csdn.net/juiceda/article/details/7568342

  • 相关阅读:
    185. [USACO Oct08] 挖水井
    JavaEE Tutorials (9)
    vjudge A
    HDU 2089 不要62
    国庆 day 2 下午
    国庆 day 2 上午
    国庆 day 1 下午
    P2899 [USACO08JAN]手机网络Cell Phone Network
    洛谷 P1690 贪婪的Copy
    洛谷 P2209 [USACO13OPEN]燃油经济性Fuel Economy
  • 原文地址:https://www.cnblogs.com/honeybusybee/p/4488805.html
Copyright © 2011-2022 走看看