zoukankan      html  css  js  c++  java
  • hihoCoder 1427 : What a Simple Research(大㵘研究)

    hihoCoder #1427 : What a Simple Research(大㵘研究)

    时间限制:1000ms
    单点时限:1000ms
    内存限制:256MB

    Description - 题目描述

      Peking University Student Folk Music Band has a history of more than 90 years. They play Chinese traditional music by Chinese traditional instruments, such as Pipa, Erhu and Guzheng, etc. Doctor Li is a member of that band, and also a former ACMer. Now he is doing some research on Chinese ancient music. Many Chinese ancient music has only five kinds of tones, which can be denoted by 'C','D','E','G', and 'A'. Given a piece of music score, Li wants to do some simple statistics.

    北京大学音乐团有着超过90年的历史。他们使用诸如琵琶、二胡与古筝等中国传统乐器演奏传统音乐。Doctor Li是乐团的一位成员,同时也是前ACMer。现在他正在研究中国古乐。许多中国古乐由五声组成,此处用 'C', 'D', 'E', 'G', 与 'A' 表示。这有一段乐谱,Li想用来做些简单的统计。
    CN

    Input - 输入

      There are no more than 20 test cases.

      In each test case:

      The first line contains two integers n and m (2<= n,m <= 20), indicating that a piece of music score is represented by an n×m matrix of tones. Only 'C','D','E','G' and 'A' can appear in the matrix.

      Then the n×m matrix follows.

      The input ends with a line of "0 0".

    测试用例不超过20组。
    对于每组测试用例:
    第一行为两个整数n与m (2<= n,m <= 20),表示一段乐谱中n×m大小的音阶矩阵。矩阵中只有 'C', 'D', 'E', 'G', 与 'A'。
    随后是n×m大小的矩阵。
    输出以一行"0 0"为结束标志。
    CN

    Output - 输出

      For each test case:

      For each kind of tone shown in the matrix, calculate the appearing times of it, and print the result in descending order according to the appearing times. If more than one kind of tones has the same appearing times, print them in the lexicographical order.

    对于每组测试用例:
    对于矩阵中的每种音阶,统计其出现次数,并照其出现次数降序输出。如果出现多种次数相同的音阶,则以字典序输出。
    CN

    Sample Input - 样例输入

    4 5
    AGCDE
    AGDDE
    DDDDD
    EEEEE
    2 4
    GADC
    CDEE
    0 0
    

    Sample Output - 样例输出

    D 8 E 7 A 2 G 2 C 1
    C 2 D 2 E 2 A 1 G 1
    

    题解

      水题,唯一的坑点估计就是不需要输出次数为0的音阶。

    代码 C++

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 struct Tone{
     5     char ton;
     6     int cnt;
     7     bool operator<(const Tone &b)const{
     8         if (cnt != b.cnt) return cnt > b.cnt;
     9         return ton < b.ton;
    10     }
    11 };
    12 int main(){
    13     int n, m, i, j;
    14     char data[25];
    15     while (scanf("%d%d ", &n, &m), n + m){
    16         Tone opt[6] = { 'A', 0, 'C', 0, 'D', 0, 'E', 0, 'G', 0, 0, 0 };
    17         for (i = 0; i < n; ++i){
    18             gets(data);
    19             for (j = 0; j < m; ++j){
    20                 switch (data[j]){
    21                 case 'A': ++opt[0].cnt; break;
    22                 case 'C': ++opt[1].cnt; break;
    23                 case 'D': ++opt[2].cnt; break;
    24                 case 'E': ++opt[3].cnt; break;
    25                 default: ++opt[4].cnt;
    26                 }
    27             }
    28         }
    29         std::sort(opt, opt + 5);
    30         for (i = 0; opt[i].cnt; ++i){
    31             printf("%c %d%c", opt[i].ton, opt[i].cnt, " 
    "[opt[i + 1].cnt == 0]);
    32         }
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    memset()函数,多用于清空数组
    Echart 词云图 上手代码 同含(echarts-wordcloud.js)最简单的教程 复制可用
    爬虫使用真实浏览器打开网页进行爬取
    jsoup 模拟登陆github网页(源代码)亲测可用 直接复制就能用
    拷贝虚拟电脑 Ubuntu 系统 含hadoop hive hbase mysql spark eclipse
    Python 连接MySQL 增删改查 直接可用(最简易,含源码)
    Python 中文词频统计,热词统计,简要分析(含上手源码)
    百度百科简介爬取(含源代码、信息领域词频数据csv格式)
    博客园博文爬取 标签爬取(含源代码)
    输入一行电报文字,将字母变成其下一字母
  • 原文地址:https://www.cnblogs.com/Simon-X/p/6109070.html
Copyright © 2011-2022 走看看