标签:
给出一张许多人的年龄和生日表。你需要从年轻到年老输出人们的名字。(没有人年龄相同)
第一行包含一个正整数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().
不会那我就从最基础的一步一步的看起来。
标签:
原文地址:http://www.cnblogs.com/chesterhu/p/4784405.html