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。注意姓名中只包含字母,

数字和空格。

输出描述

对于每组数据,输出nn行姓名。

输入样例

2
1
FancyCoder 1996
2
FancyCoder 1996
xyz111 1997

输出样例

FancyCoder
xyz111
FancyCoder
 1 #include <stdio.h>
 2 #include <ctype.h>
 3 #include <string.h>
 4 #include <stdlib.h>
 5 #include <limits.h>
 6 #include <math.h>
 7 #include <algorithm>
 8 #include <stack>
 9 #include <queue>
10 #include <vector>
11 #include <map>
12 #include <set>
13 #include <string>
14 #include <sstream>
15 using namespace std;
16 /*
17 #define lson l,m,rt<<1
18 #define rson m+1,r,rt<<1|1
19
20 typedef long long LL;
21 const double pi=4.0*atan(1.0);
22 const int MAXN=1000005;*/
23 struct node{
24     char s[500];
25     int year;
26 };
27 node a[200];
28 int cmp(node x,node y)
29 {
30     return x.year>y.year;
31 }
32 int main()
33 {
34     int T;
35     int i,j,k;
36     int len;
37     int n;
38     while(scanf("%d",&T)!=EOF)
39     {
40         while(T--)
41         {
42             scanf("%d",&n);
43             printf("before getchar()\n");
44             //getchar();
45             printf("after getchar()\n");
46             for(i=0;i<n;i++)
47             {
48                  printf("before gets()\n");
49                 gets(a[i].s);
50                  printf("after gets()\n");
51                 len=strlen(a[i].s);
52                 int c=0;
53                 for(j=len-4;j<len;j++)
54                 {
55                     c=c*10+(a[i].s[j]-‘0‘);
56                 }
57                 a[i].s[len-5]=‘\0‘;
58                 a[i].year=c;
59             }
60             sort(a,a+n,cmp);
61             for(i=0;i<n;i++)
62                 printf("%s\n",a[i].s);
63         }
64     }
65     return 0;
66 }

不会,为什么???还是因为不太懂gets(),和getchar().

不会那我就从最基础的一步一步的看起来。

				
时间: 2024-07-29 05:16:34

A problem of sorting的相关文章

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 contai

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 \

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","

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

H4P2[Sorting Words]反思

Problem 2: Sorting Words Description Implement a program that reads from a user-specified input file, and stores the words into a vector, then sort the vector. A function object should be passed to sort(), which accepting two strings as parameters. I

best code #54 div 2 A 水

A problem of sorting Accepts: 443 Submissions: 1696 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description There are many people's name and birth in a list.Your task is to print the name from young to old

UVA - 10474 - Where is the Marble? (基数排序)

UVA - 10474 Where is the Marble? Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginni

Analysis of Algorithms--preface

Analysis of Algorithms: First part of the course is focused on analysis. Second part of the course is focused on design. The analysis of algorithm is the theoretical study.(算法分析是理论研究) The theoretical study of computer-program performance and resource

AtCoder Grand Contest 038 简要题解

从这里开始 比赛目录 Problem A 01 Matrix Code #include <bits/stdc++.h> using namespace std; typedef bool boolean; const int N = 1e3 + 5; int W, H, A, B; int main() { scanf("%d%d%d%d", &W, &H, &A, &B); for (int i = 0; i < W; i++) {