hihoCoder 1427 : What a Simple Research(大㵘研究)
hihoCoder #1427 : What a Simple Research(大㵘研究)
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 (<= n,m <= ),表示一段乐谱中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++
#include <cstdio>
#include <cstring>
#include <algorithm>
struct Tone{
char ton;
int cnt;
bool operator<(const Tone &b)const{
if (cnt != b.cnt) return cnt > b.cnt;
return ton < b.ton;
}
};
int main(){
int n, m, i, j;
char data[];
while (scanf("%d%d ", &n, &m), n + m){
Tone opt[] = { 'A', , 'C', , 'D', , 'E', , 'G', , , };
for (i = ; i < n; ++i){
gets(data);
for (j = ; j < m; ++j){
switch (data[j]){
case 'A': ++opt[].cnt; break;
case 'C': ++opt[].cnt; break;
case 'D': ++opt[].cnt; break;
case 'E': ++opt[].cnt; break;
default: ++opt[].cnt;
}
}
}
std::sort(opt, opt + );
for (i = ; opt[i].cnt; ++i){
printf("%c %d%c", opt[i].ton, opt[i].cnt, " \n"[opt[i + ].cnt == ]);
}
}
return ;
}
hihoCoder 1427 : What a Simple Research(大㵘研究)的更多相关文章
- A simple test
博士生课程报告 视觉信息检索技术 博 士 生:施 智 平 指导老师:史忠植 研究员 中国科学院计算技术研究所 2005年1月 目 ...
- JSON库的使用研究(二)
Java 中哪个 JSON 库的解析速度是最快的? 这个问题有意义吗?各个JSON库的性能差距不大?呵呵,差距大不大,自己往下看吧! 这个问题我们应该分为以下四个维度进行研究: 1.序列化 2.反序列 ...
- SLAM领域牛人、牛实验室、牛研究成果梳理
点击公众号"计算机视觉life"关注,置顶星标更快接收消息! 本文阅读时间约5分钟 对于小白来说,初入一个领域时最应该了解的当然是这个领域的研究现状啦.只有知道这个领域大家现在正在 ...
- 看完它,你就全懂了十大Wifi芯片原厂!
看完它,你就全懂了十大Wifi芯片原厂! 来源:全球物联网观察 概要:不知不觉中,WiFi几乎已攻占了整个世界.现在只要你上网,可能就离不开WiFi了. 2014年是物联网WiFi市场关键的转折期 ...
- Java 下的 JSON库性能比较:JSON.simple
JSON已经成为当前服务器与WEB应用之间数据传输的公认标准,不过正如许多我们所习以为常的事情一样,你会觉得这是理所当然的便不再深入思考了.我们很少会去想用到的这些JSON库到底有什么不同,但事实上它 ...
- JSON库之性能比较:JSON.simple VS GSON VS Jackson VS JSONP
从http://www.open-open.com/lib/view/open1434377191317.html 转载 Java中哪个JSON库的解析速度是最快的? JSON已经成为当前服务器与WE ...
- 对html中iframe的研究
虽然平时不怎么用iframe,但经常在网上听一些前辈说iframe怎样怎样,今天索性对iframe来个大研究,那样就不必去记那些条条框框了,自己体验一遍比看什么都好. 创建两个文件一个index.ht ...
- 开源 JSON 库解析性能对比( Jackson / Json.simple / Gson )
Json 已成为当前服务器与 web 应用之间数据传输的公认标准. 微服务及分布式架构经常会使用 Json 来传输此类文件,因为这已经是 webAPI 的事实标准. 不过正如许多我们习以为常的事情一样 ...
- Json学习总结(2)——Java 下的 JSON库性能比较:JSON.simple vs. GSON vs. Jackson vs. JSONP
JSON已经成为当前服务器与WEB应用之间数据传输的公认标准,不过正如许多我们所习以为常的事情一样,你会觉得这是理所当然的便不再深入思考了.我们很少会去想用到的这些JSON库到底有什么不同,但事实上它 ...
随机推荐
- Git的.gitignore文件配置
.gitignore是Git工具的配置文件,用于屏蔽某些文件上传到线上. 创建.gitignore 在window系统中,不允许新建文件名以"."开头的文件,所以通过git bas ...
- java实现excel表格导出数据
/** * 导出清单 eb中 firstRow(EntityBean) 列表第一行数据,键值对(不包含序号)例:("name","姓名") * data(Ent ...
- smarty 模板几个例子
一.assign和display方法的使用以及几个变量调节器 header("content-type:text/html;charset=utf-8");//加载Smarty引擎 ...
- Leetcode: Sort Transformed Array
Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...
- eclipse安装svn
- WebApi身份认证解决方案:Basic基础认证
前言:最近,讨论到数据库安全的问题,于是就引出了WebApi服务没有加任何验证的问题.也就是说,任何人只要知道了接口的url,都能够模拟http请求去访问我们的服务接口,从而去增删改查数据库,这后果想 ...
- False 等效值
False 等效值 下面这些值将被计算出 false (also known as Falsy values): false undefined null 0 NaN 空字符串 ("&quo ...
- thinkPHP 5.0.x 使用SQLite3 进行缓存设置 Cache
1. 配置 thinkPHP cache [application/config.php] 把type设置为sqlite3(默认是小写,第一个字母不区分大小写) 把path换成db,并指定sqlite ...
- PHP 将下划线命名 转换为 驼峰式命名
function convertUnderline($str , $ucfirst = true) { $str = ucwords(str_replace('_', ' ', $str)); $st ...
- Sql Server 中一个非常强大的日期格式化函数
Sql Server 中一个非常强大的日期格式化函数Select CONVERT(varchar(100), GETDATE(), 0)-- 05 16 2006 10:57AMSelect CONV ...