poj 2021 Relative Relatives
来源:互联网 发布:ubuntu 安装 交换分区 编辑:程序博客网 时间:2024/05/01 00:09
Description
Today is Ted's 100th birthday. A few weeks ago, you were selected by the family to contact all of Ted's descendants and organize a surprise party. To make this task easier, you created an age-prioritized list of everyone descended from Ted. Descendants of the same age are listed in dictionary order.
The only materials you had to aid you were birth certificates. Oddly enough, these birth certificates were not dated. They simply listed the father's name, the child's name, and the father's exact age when the baby was born.
The only materials you had to aid you were birth certificates. Oddly enough, these birth certificates were not dated. They simply listed the father's name, the child's name, and the father's exact age when the baby was born.
Input
Input to this problem will begin with line containing a single integer n indicating the number of data sets. Each data set will be formatted according to the following description.
A single data set has 2 components:
Note:
A single data set has 2 components:
- Descendant Count - A line containing a single integer X (where 0 < X < 100) indicating the number of Ted's descendants.
- Birth Certificate List - Data for X birth certificates, with one certificate's data per line. Each certificate's data will be of the format "FNAME CNAME FAGE" where:
- FNAME is the father's name.
- CNAME is the child's name.
- FAGE is the integer age of the father on the date of CNAMEs birth.
- FNAME is the father's name.
Note:
- Names are unique identifiers of individuals and contain no embedded white space.
- All of Ted's descendants share Ted's birthday. Therefore, the age difference between any two is an integer number of years. (For those of you that are really picky, assume they were all born at the exact same hour, minute, second, etc... of their birth year.)
- You have a birth certificate for all of Ted's descendants (a complete collection).
Output
For each data set, there will be X+1 lines of output. The first will read, "DATASET Y", where Y is 1 for the first data set, 2 for the second, etc. The subsequent X lines constitute your age-prioritized list of Ted's descendants along with their ages using the format "NAME AGE". Descendants of the same age will be listed in dictionary order.
http://poj.org/problem?id=2021
代码:
#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct people{int age;char name[20];}dec;int cmp(const void *a,const void *b){dec *deca = (dec *)a;dec *decb = (dec *)b;if(deca->age != decb->age) return decb->age - deca->age;else return strcmp(deca->name,decb->name);}int main(){int n, count, fage[100];char fname[100][20],cname[100][20];dec a[100];scanf("%d",&n);for(int i = 1; i <= n; i++){scanf("%d",&count);for(int j = 0; j < count; j++)scanf("%s %s %d",fname[j],&cname[j],&fage[j]);a[0].age = 100;strcpy(a[0].name,"Ted");int m = 1;for(int j = 0; j < m; j++){for(int k = 0; k < count; k++){if(strcmp(a[j].name,fname[k]) == 0){a[m].age = a[j].age - fage[k];strcpy(a[m].name,cname[k]);m++;}}}qsort(a,m,sizeof(a[0]),cmp);printf("DATASET %d\n",i);for(int l = 1; l < m; l++)printf("%s %d\n",a[l].name,a[l].age);}system("pause");}
0 0
- POJ 2021 Relative Relatives
- poj 2021 Relative Relatives
- poj 2021 Relative Relatives
- poj 2021 Relative Relatives
- Poj 2021 Relative Relatives
- poj 2021 Relative Relatives 排序
- poj---Relative Relatives
- POJ2021 Relative Relatives
- hdu 1311 Relative Relatives
- pku 2021 Relative Relatives(相对关系的数据结构)
- poj 2407 Relatives
- POJ 2407 Relatives
- poj - 2407 - Relatives
- poj 2407 Relatives
- Poj 2407 Relatives
- poj 2407 Relatives
- POJ 2407 Relatives
- POJ 2407 Relatives
- POJ_2253_Frogger_最短路
- android 实用闹钟开发过程记(一)--创建数据库
- rsync+ inotify实时同步
- android 实用闹钟开发过程记(二)--sqlite数据库的操作
- About Bluetooth LE
- poj 2021 Relative Relatives
- HDU 4891 The Great Pan (字符串处理)
- Android实用闹钟开发(三)---AlarmManager和Calendar
- Android 一键清理动画
- android闹钟开发(四)--音乐播放与音量调节
- android屏幕适配
- MySQL数据库插入中文出现“Incrrect Strng value '\xE9\x9C\x82'"错误
- 字典树 详解
- 去掉ExpandableListView的箭头图标