POJ 2218 Does This Make Me Look Fat?
来源:互联网 发布:网络硬件设备 编辑:程序博客网 时间:2024/06/08 12:51
Does This Make Me Look Fat?
Description
As the host of a popular daytime television talk show, you are working through the details of an upcoming episode on dieting. Your guest is the controversial Dr. Kevorkian, who has recently invented his own weight-loss plan, "Do You Want To Diet?" that guarantees to reduce your body weight by 1 pound every day.
You have a number of dieters scheduled to be on the show who have all been using Dr. Kevorkian?s new plan. You want to make the episode more dramatic by introducing your guests in decreasing order of their weights on the day of the show. The problem is that the forms you had them fill out only requested the following information: Name, Days on the diet, Weight at start of diet. Hopefully you can dredge up those long-forgotten math skills before the filming time tonight!
You have a number of dieters scheduled to be on the show who have all been using Dr. Kevorkian?s new plan. You want to make the episode more dramatic by introducing your guests in decreasing order of their weights on the day of the show. The problem is that the forms you had them fill out only requested the following information: Name, Days on the diet, Weight at start of diet. Hopefully you can dredge up those long-forgotten math skills before the filming time tonight!
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.
A single data set has 3 components:
Here are some facts that may be useful:
A single data set has 3 components:
- Start line - A single line, "START"
- Dieter list - A series of 1 to 10 (inclusive) single lines consisting of three fields, with each field separated from the others by a single space:
- Name - The dieter?s first name. This will be a text string containing 1 to 20 (inclusive) alphanumeric characters (no spaces).
- Days On Diet - The number of days the dieter has been on the "Do You Want To Diet" as of the day of the talk show. This will be a non-zero positive integer strictly less than 1000.
- Starting Weight - The weight, in pounds, of the dieter just before starting the diet. This will be a non-zero positive integer strictly less than 10,000.
- Name - The dieter?s first name. This will be a text string containing 1 to 20 (inclusive) alphanumeric characters (no spaces).
- End line - A single line, "END"
Here are some facts that may be useful:
- All dieters lost exactly 1 pound every day they were on the diet, as advertised.
- Nobody stayed on the diet long enough to weigh less than 1 pound at the time of the show.
- All dieters in a given input set will have different weights on the day of the show.
- All dieters in a given input set will have different names.
Output
For each input data set, there will be exactly one output set, and there will be exactly one blank line separating output sets.
A single output set consists of a series of lines, each containing the Name of one of the dieters from the Dieter list. The list will be sorted in descending order according to weight at the time of the TV show. All dieters must be listed.
A single output set consists of a series of lines, each containing the Name of one of the dieters from the Dieter list. The list will be sorted in descending order according to weight at the time of the TV show. All dieters must be listed.
Sample Input
STARTJoe 10 110ENDSTARTJames 100 150Laura 100 140Hershey 100 130ENDSTARTHershey0 1 5Hershey2 1 3Hershey1 1 4Hershey3 1 2END
Sample Output
JoeJamesLauraHersheyHershey0Hershey1Hershey2Hershey3题目大意:有一个专家发明了一个减肥食谱,它可以让人每天减肥1磅。给出一些使用这些食谱的人的姓名、使用时间以及使用食谱之前的重量,按目前体重从高到低的顺序输出这些人的名字。
解题思路:使用结构体存储每个减肥者的信息,按照体重减去天数自大到小排列即可。
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef struct{char name[25];int day;int weight;}dieter;dieter dtr[15];int cmp(dieter a,dieter b){return a.weight - a.day > b.weight - b.day;}int main(){int i,j,k;char opt1[10],opt2[10];while(scanf("%s",opt1) != EOF && strcmp("START",opt1) == 0){for(i = 0;i < 11;i++){scanf("%s",dtr[i].name);if(strcmp(dtr[i].name,"END") == 0)break;scanf("%d %d",&dtr[i].day,&dtr[i].weight);}sort(dtr,dtr + i,cmp);for(j = 0;j < i;j++)printf("%s\n",dtr[j].name);printf("\n");}return 0;}
0 0
- POJ 2218 Does This Make Me Look Fat?
- POJ 2218 Does This Make Me Look Fat? G++
- TOJ 2043.Does This Make Me Look Fat?
- tar: This does not look like a tar archive
- This does not look like a tar archive - 解决方法
- Does XML let me make up my own tags?
- tar解压文件时出错-This does not look like a tar archive
- tar.gz 解压出现 tar :This does not look like a tar archive 解决
- Look, This Girl
- What does he look like
- Make Correct Code Look Correct
- linux下安装.tar的压缩文件时报错 tar: This does not look like a tar archive
- Achievements make me alive!
- Take a look at this
- This is me!
- This is me.
- Give Me This Pizza
- Don’t Make Me Think
- 查询局域网电脑的IP,端口号,MAC地址(黑客技术入门)
- 风不停息!我的第一个博客
- 游戏编程中的人工智能技术-神经网络入门(二)
- Retrofit2.0 上传文件和下载文件
- C++虚函数声明和定义以及g++编译遇到的一些问题
- POJ 2218 Does This Make Me Look Fat?
- java 操作excel
- 封装、继承和多态的具体实例
- CMUSphinx-在你开始之前
- android Button在点击的监听代码里获取自身对象
- 关于python中pymysql数据编码问题
- ubuntu 14.04 linux下wifi驱动安装使用的一些笔记
- ubuntu 升级 openssl
- 关于Qt5.70你必须知道的那点事