UVA 10420 List of Conquests
2015-07-26 19:56
841 查看
题目
战利品列表分析
题目给出列表行数n,接下来
n行每行给出城市名(
第一个单词)和人名(并没有什么卵用),统计每个城市有几个人头数(
ˊ_>ˋ)并以字典序排序打出。
思路
每行取出城市名,将其人头数+1;qsort()排序。
代码
#include <stdio.h> #include <string.h> #include <stdlib.h> int cmp(const void* a,const void* b) { return strcmp((char*)a, (char*)b); } int main(void) { int n, i, j, k, c; char country[2050][80], tmp[80]; scanf("%d", &n); getchar(); for (i = 0, j = 0; i < n; i++) { fgets(tmp, 80, stdin); for (k = 0; tmp[k] != ' '; k++) country[j][k] = tmp[k]; j++; } qsort(country, n, sizeof(country[0]), cmp); for (i = 0, c = 1; i < n; i++) if (strcmp(country[i], country[i+1]) == 0) { c++; } else { printf("%s %d\n", country[i], c); c = 1; } return 0; }
相关文章推荐
- Altuim designer 导入PCB,出现错误some nets were not able to be matched
- HDUOJ Number Sequence 题目1005
- HDU 1937 J - Justice League
- iOSUI篇--动画(Core Animation)总结
- Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi
- 【瞎搞】 HDU 5312 Sequence
- HDU 5312 Sequence
- Android中多线程编程(三)Handler更新UI的方式
- ListBuffer、ArrayBuffer、Queue、Stack操作代码实战
- leetcode[96]:Unique Binary Search Trees
- 实现Guice下的单元测试中mybatis数据库操作的回滚.
- MiniGui 多窗口程序(一)
- Implement Stack using Queues && Implement Queue using Stacks (LeetCode)
- leetcode第225题:Implement Stacks using Queues
- easyui searchbox
- UESTC 250 windy数(数位DP)
- UITextField限制文本长度 , UI控件 自适应宽高 。
- ZOJ - 2548 Prerequisites?
- 用Fluentd实现收集日志到HDFS(上)
- [iOS]类似新浪微博或者人人客户端中,中间UITabBarItem只有图片,使图片居中的方法