• 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 }
  • 相关阅读:
    一个项目多个App项目搭建
    mac 配置sencha touch环境
    mac 配置pylucene
    django博客开发
    xampp添加 django支持
    mac安装apache的mod_wsgi模块
    修改xampp默认sql密码
    xampp 安装 mysql-python
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
    MySQL问题解决:-bash:mysql:command not found
  • 原文地址:https://www.cnblogs.com/Simon-X/p/6109070.html
Copyright © 2020-2023  润新知