zoukankan      html  css  js  c++  java
  • 1055 气球

    1055 气球

     

     时间限制: 1 s
     空间限制: 128000 KB
     题目等级 : 白银 Silver
     
     
    题目描述 Description

    在刚刚过去的六一节里(虽然我们已经不是儿童了,也可以庆祝一下啊,哈哈),游乐园的天空中飘满了气球,明明对这些气球突然有了兴趣,他需要你的帮助!

    你将会被告知气球的数量以及每个气球的颜色

    相同颜色的气球数量被称为这种颜色的频率。

    输入描述 Input Description

    输入(balloon.in):第一行为N(N<=100),接下来的N行为1——N个气球的颜色(单词的长度不超过14个字母)!

    输出描述 Output Description

    输出 (balloon.out):第一行为气球颜色的总数.

    从第二行开始,按照以下规则输出:

    先输出最大频率(占一行);

    再按词典顺序输出是这种频率的颜色,一种颜色占一行。

    对其它所有频率按从大到小的顺序进行相同的操作(要保证操作了所有的频率与颜色)。

    样例输入 Sample Input

    样例输入1:

        5
    green
    red
    blue
    red
    red

    样例输入 2:

        3
    pink
    orange
    pink

    样例输出 Sample Output

    样例输出 1:

        3

        3

        red

        1

        blue

    green

    样例输出 2:

        2

        2

        pink

        1

        orange

    数据范围及提示 Data Size & Hint
     

    分类标签 Tags 

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    using namespace std;
    string color[1000],c;
    int a[1000],flag=0,tmp=0;
    int n,u,up,count=0;
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            cin>>c;
            for(int j=1;j<i;j++){
                if(c==color[j]){
                    a[j]++;flag=1;
                }
            }
            if(flag==0){
                count++;color[i]=c;a[i]++;
            }
            flag=0;
        }
        printf("%d
    ",count);
        while(count--){
            up=a[1];u=1;//排序:a[i]第一关键字 color[i]第二关键字
            for(int i=1;i<=n;i++){
                if(a[i]>up){
                    up=a[i];u=i;
                }
                if(a[i]==up){
                    if(color[i]<color[u]){
                        up=a[i];u=i;
                    }
                }
            }
            if(up!=tmp){//判断数量重复情况 
                cout<<up<<endl<<color[u]<<endl;
                a[u]=0;tmp=up;
            }
            else{
                cout<<color[u]<<endl;
                a[u]=0;
            }
        }
        return 0;
    }
  • 相关阅读:
    GNU make manual 翻译(九十九)
    GNU make manual 翻译( 九十五)
    Shell的 for 循环小例子
    makefile中对目录遍历的小例子
    GNU make manual 翻译(九十三)
    GNU make manual 翻译( 一百)
    GNU make manual 翻译( 九十七)
    GNU make manual 翻译( 九十八)
    mapserver4.8.3 的readme.win32的中文翻译文件
    遥控器编程
  • 原文地址:https://www.cnblogs.com/shenben/p/5557544.html
Copyright © 2011-2022 走看看