zoj1745 Are We There Yet?
来源:互联网 发布:猎天使魔女 知乎 编辑:程序博客网 时间:2024/05/16 17:27
Description
Input
Each input line represents a new game. Each input line contains at least two and at most 21 integers separated by whitespace. The integers represent locations along the hall, expressed in units of feet. Joey begins each game at location 0 feet. The first integer on an input line is the location of the cookie. This integer is guaranteed to be different from 0. The remaining integers represent locations Joey moves to, in order. Joey will never move more than 5280 feet from his original location. Joey will always reach the cookie in each game, and this will be the last move on the input line. Your program should stop processing input lines when the cookie is located at 5280 feet (a mile from the center of the hall is way too far for Joey to go for only one cookie).
Output
For each location that Joey moves to, determine whether he is warmer, colder, the same, or has reached the cookie. Have a blank line between the output for different input lines. Follow the format in the Sample Output.
Sample Input
5 10 11 12 3 4 5
3 10 10 7 3
12 5 -3 1 4 6 7 8 9 12
5280 10
Sample Output
Moving from 0 to 10: same.
Moving from 10 to 11: colder.
Moving from 11 to 12: colder.
Moving from 12 to 3: warmer.
Moving from 3 to 4: warmer.
Moving from 4 to 5: found it!
Moving from 0 to 10: colder.
Moving from 10 to 10: same.
Moving from 10 to 7: warmer.
Moving from 7 to 3: found it!
Moving from 0 to 5: warmer.
Moving from 5 to -3: colder.
Moving from -3 to 1: warmer.
Moving from 1 to 4: warmer.
Moving from 4 to 6: warmer.
Moving from 6 to 7: warmer.
Moving from 7 to 8: warmer.
Moving from 8 to 9: warmer.
Moving from 9 to 12: found it!
Source
#include <iostream>
#include<cstdio>
#include<cmath>//使用abs()需要
#include<cstdlib>//使用abs()需要
using namespace std;
int main()
{
int now,last,c;
int flag=0;
while(scanf("%d",&c)&&c!=5280)
{
last=0;
if(flag++)//还是有点巧妙的,格式输出的需要。如何处理换行。牢记
printf("\n");
while(scanf("%d",&now)!=EOF)
{
if(now==c)
{
printf("Moving from %d to %d: found it!\n",last,now);
break;//每组的最后一个数据肯定是now==c,利用这个作为每组的分隔
}
else if(abs(now-c)>abs(last-c))
printf("Moving from %d to %d: colder.\n",last,now);
else if(abs(now-c)<abs(last-c))
printf("Moving from %d to %d: warmer.\n",last,now);
else if(abs(now-c)==abs(last-c))
printf("Moving from %d to %d: same.\n",last,now);
last=now;
}
}
return 0;
}
- zoj1745 Are We There Yet?
- Are We There Yet? (zoj1745)
- Are We There Yet?
- fjnu 1298 Are We There Yet?
- ZOJ 1745 Are We There Yet?
- ZOJ 1745 Are We There Yet?
- zoj 1745 Are We There Yet?
- zoj 1745 Are We There Yet?
- Couldn't get connection because we are at maximum connection count (150/150) and there are none 异常解决
- Couldn't get connection because we are at maximum connection count (50/50) and there are none av
- apple ——we are - are we
- English---There is / There are
- We Are The World
- We are approaching graduation
- Are we ready?
- So Here We Are
- We are a team!!!
- we are on grails
- c++ 模板详解(一)
- Swift 中使用 SwiftyJSON 制作一个比特币价格 APP
- 关于DMA传输外设地址的说明
- hdu1045 Fire Net(二分图最大匹配)
- Project Euler:Problem 90 Cube digit pairs
- zoj1745 Are We There Yet?
- HDU 3681 Prison Break(状压DP + 二分)
- H.264 基础及 RTP 封包详解
- oracle数据库---sqlplus介绍
- 1027
- JS视频播放
- NYOJ 1057 寻找最大数(三)
- NSString / NSData / char* 类型之间的转换
- linux 之makefile语法学习1