hdu 5427 A problem of sorting
来源:互联网 发布:淘宝运营商是真的吗 编辑:程序博客网 时间:2024/06/05 08:20
题目链接:<a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=5427">点击打开链接</a>
题意:题目就是给出人的名字和出生年,并且不会有两个人是同一年,让按照每个人年龄从小到大输出对应的名字。
题解:这个题目有个难点就是名字的输入可能有空格,最后输出的时候得把空格都输出,所以在输入的时候要将名字和出生年当成一个字符串一起输入,然后把字符串的后面4位
存在结构体的data中,进行比较,最后对应输出名字。
输入的时候要用cin.getline(s,210) 字符串及其长度,还有提前加getchar();
注意结构体使用,sort中cmp的使用,以及字符串s后面加结束符。
代码:
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;struct people{ char name[110]; int data;};struct people a[110];int cmp(people b,people c){ return b.data>c.data;}char s[210];int main(){ int t,n,len; cin>>t; while(t--) { cin>>n; getchar(); for(int i=0;i<n;i++) { cin.getline(s,210); len=strlen(s); a[i].data=1000*s[len-4]+100*s[len-3]+10*s[len-2]+s[len-1]; len-=5; s[len]='\0'; strcpy(a[i].name,s); } sort(a,a+n,cmp); for(int i=0;i<n;i++) cout<<a[i].name<<endl; } return 0;}
0 0
- hdu 5427 A problem of sorting
- hdu 5427 A problem of sorting 排序
- HDU 5427 A problem of sorting 水题
- hdu 5427 A problem of sorting
- hdu 5427 A problem of sorting
- HDU 5427 A problem of sorting
- HDU 5427 A problem of sorting
- hdu 5427 A problem of sorting 排序
- hdu 5427 A problem of sorting(水)
- hdu 5427 A problem of sorting 解题报告
- HDU 5427-A problem of sorting(字符串处理)
- 【map容器+string】hdu 5427 A problem of sorting
- HDU——5427 A problem of sorting
- A problem of sorting
- HDOJ 5427 A problem of sorting
- HDU 5431/BC 54A A problem of sorting
- HDU5429----A problem of sorting
- HDU 5427 A problem of sorting(字符串处理+排序)——BestCoder Round #54(div.2)
- How can I become data scientist?FAQ
- HUST 1010The Minimum Length
- HDU 5430-Reflect(欧拉函数求圆内反射方法数)
- VS2010/MFC编程入门之十一中(对话框:模拟对话及其弹出过程)学习时的一个注意点
- SpringMVC—接收请求参数和页面传参
- hdu 5427 A problem of sorting
- VS2013开发上位机并调用MSCcommm控件的方式
- CCF 201409-4最优配餐(BFS)
- 收到批评的开心
- iOS——UISegmentedControl 的用法
- 小四轴调试记录
- UVA1592 Database
- 谈谈我所理解的Hibernate
- FTP 跳转攻击