UVA-10420 List of Conquests
来源:互联网 发布:voip网络电话软件 编辑:程序博客网 时间:2024/06/05 17:12
2016-07-16
UVA - 10420 List of Conquests
题目大意:输入一个国家和一个女人的名字,统计每个国家有多少人,按字典序输出。所以名字并没有什么卵用。
解题思路:读入国家,排序,遍历,与前一个相同则人数 +1,不同就输出。
注意:先进行排序的话会简单很多。
#include <iostream>#include <cstdio>#include <cstring>#include <stdlib.h>using namespace std;char str1[10000][10000];char str2[10000][10000];int num[10000];char country[10000][1000];int temp = 0;int comp ( const void*a , const void *b ) { char *_a = (char*)a; char *_b = (char*)b; return strcmp(_a,_b);}int main() { memset ( num , 0 , sizeof(num) ); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> str1[i]; gets(str2[i]); } qsort( str1 , n , sizeof(str1[0]) , comp ); strcpy(country[0],str1[0]); num[0]++; temp++; for (int i = 0; i < n-1; i++) { if ( !strcmp( str1[i] , str1[i+1] ) ) num[temp-1]++; else { strcpy( country[temp] , str1[i+1] ); num[temp]++; temp++; } } for (int i = 0; i < temp; i++) cout << country[i] << " " << num[i] << endl; return 0;}
0 0
- UVa 10420 List of Conquests
- UVA 10420 - List of Conquests
- uva 10420 List of Conquests
- UVA 10420 - List of Conquests
- UVa 10420 - List of Conquests
- UVa 10420 - List of Conquests
- UVa 10420 - List of Conquests
- UVA 10420 - List of Conquests
- UVa 10420 - List of Conquests
- UVA 10420 List of Conquests
- uva 10420 - List of Conquests
- UVa - 10420 - List of Conquests
- uva 10420 List of Conquests
- uva - 10420 - List of Conquests
- UVa 10420 - List of Conquests
- UVA 10420 - List of Conquests
- UVa 10420 - List of Conquests
- uva 10420 - List of Conquests
- Android动画之视图动画
- 如何在HTML5中使用SVG
- git终端命令
- android项目之记事本-1(已上线)
- LeetCode题目索引-难度及面试频率
- UVA-10420 List of Conquests
- 一个过来人的经验
- mysql安装 for windows
- 系统架构师谈企业应用架构之系统设计规范与原则1
- 【老经验】shell命令和PHP Cron job以及tmux
- 冒泡排序
- 每秒处理10万订单乐视集团支付架构
- OpenCV学习C++接口:图像遍历+像素压缩
- 弹出框(警告框)iOS9.0使用方法