hdu 5427 A problem of sorting

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5427

A problem of sorting

Description

There are many people‘s name and birth in a list.Your task is to print the name from young to old.(There is no pair of two has the same age.)

Input

First line contains a single integer $T \leq 100$ which denotes the number of test cases.

For each test case, there is an positive integer $n\ (1 \leq n \leq 100)$ which denotes the number of people,and next $n$ lines,each line has a name and a birth‘s year(1900-2015) separated by one space.

The length of name is positive and not larger than 100.Notice name only contain letter(s),digit(s) and space(s).

Output

For each case, output $n$ lines.

Sample Input

2
1
FancyCoder 1996
2
FancyCoder 1996
xyz111 1997

Sample Output

FancyCoder
xyz111
FancyCoder

字符串简单题。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
using std::set;
using std::sort;
using std::pair;
using std::swap;
using std::queue;
using std::multiset;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 110;
const int INF = 0x3f3f3f3f;
typedef unsigned long long ull;
struct Node {
	int age;
	char name[N];
	inline bool operator<(const Node &x) const {
		return age > x.age;
	}
}A[N];
int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w+", stdout);
#endif
	int t, n;
	char buf[200], digit[5];
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		getchar();
		rep(i, n) {
			gets(buf);
			int v, j = 0, len = strlen(buf);
			for (; j < 4; j++) digit[j] = buf[len - 4 + j];
			digit[j] = ‘\0‘; v = atoi(digit);
			buf[len - 5] = ‘\0‘;
			A[i].age = v, strcpy(A[i].name, buf);
		}
		sort(A, A + n);
		rep(i, n) printf("%s\n", A[i].name);
	}
	return 0;
}
时间: 2024-10-13 16:19:31

hdu 5427 A problem of sorting的相关文章

HDU 5427 A problem of sorting 水题

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5427 A problem of sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1447    Accepted Submission(s): 554 Problem Description There are many p

hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 52 Problem Description A topological sort or topological ordering of a directed

HDU 3549 Flow Problem ( 最大流 -EK 算法)

C++,G++的读取速度差距也太大了 Flow Problem 题意:n,m表示n个点m条有向带权边 问:从1-n最大流多少 裸最大流,拿来练手,挺不错的 #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> const int N = 210; #define

A problem of sorting

A problem of sorting 问题描述 给出一张许多人的年龄和生日表.你需要从年轻到年老输出人们的名字.(没有人年龄相同) 输入描述 第一行包含一个正整数T(T \leq 5)T(T≤5),表示数据组数. 对于每组数据,第一行包含一个正整数n(1 \leq n \leq 100)n(1≤n≤100),表示人数,接下来n行,每 行包含一个姓名和生日年份(1900-2015),用一个空格隔开.姓名长度大于0且不大于100.注意姓名中只包含字母, 数字和空格. 输出描述 对于每组数据,输出

HDU 3549 Flow Problem 网络最大流问题 Edmonds_Karp算法

题目链接:HDU 3549 Flow Problem Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 8218    Accepted Submission(s): 3824 Problem Description Network flow is a well-known difficult problem f

bc #54 A problem of sorting

A problem of sorting Accepts: 445 Submissions: 1706 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 给出一张许多人的年龄和生日表.你需要从年轻到年老输出人们的名字.(没有人年龄相同) 输入描述 第一行包含一个正整数T(T \leq 5)T(T≤5),表示数据组数. 对于每组数据,第一行包含一个正整数n(1 \leq n \

HDU Hotaru&#39;s problem(Manacher算法+贪心)

manacher算法详见 http://blog.csdn.net/u014664226/article/details/47428293 题意:给一个序列,让求其最大子序列,这个子序列由三段组成,第一段和第二段对称,第一段和第三段一样. 思路:首先利用Manacher算法求出以任意两个相邻元素为中心的回文串长度,用a[i]表示i-1,i为中心的回文串长度的一半, 那么问题就转化成了求最大的x,使得a[i]>=x,a[i+x]>=x,这一步可以贪心来做. 将a[i]从大到小排序(间接排序保留

网络流 HDU 3549 Flow Problem

网络流 HDU 3549 Flow Problem 题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法进行求解,注意的问题有两个: 1. 每次增广的时候,反向流量也要进行更行,一开始没注意,WA了几次 ORZ 2. 对于输入的数据,容量要进行累加更新. // 邻接矩阵存储 #include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const i

Volume 1. Elementary Problem Solving :: Sorting/SearchingUva 340,10420,10474,152,299,120,156,400,755

刘汝佳 算法入门 第一版 Uva题目集合(四) Uva 340 #include<stdio.h> #include<string.h> int h[1001][2],g[1001]={0}; int n,m=0,i,j,k,a,b,o; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","