fjnu 1298 Are We There Yet?

本文介绍了一款名为FindtheCookie的游戏模拟程序。该程序通过模拟游戏角色Joey在一条虚拟长廊中寻找隐藏饼干的过程,展示了如何使用编程解决简单的寻物问题。Joey从走廊中间开始移动,每一步程序会告诉他离饼干更近还是更远,直至找到饼干。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

Laurie's little brother Joey has been playing Find the Cookie with her. However, after the 32,767th time, Laurie is tired of it. She wants to write a program to keep the boy occupied. Write a program to simulate a game of Find the Cookie. The game takes place in a long narrow hall, so Joey can only move forward and backward, not right or left. At the beginning of each game, a cookie is placed in the hall (not at the center of the hall) and Joey starts at the center of the hall. Joey attempts to find the cookie. He does this by moving to another point in the hall, whereupon the computer tells him whether he is "warmer" (he has moved closer to the cookie than his last position), "colder" (he has moved farther away from the cookie than his last position), "same" (he has not moved closer or farther away from the cookie), or he has reached the cookie. Joey continues until he exactly reaches the location of the cookie, which always happens within 20 moves.

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!
KEY:把每次输入的位置跟cookie比较,看大小;
Source:

#include
<iostream>
#include
<math.h>
using namespace std;

int cookie;
int s1,s2;

void find()
{
    
int t;
    cin
>>t;
    s1
=0;
    s2
=t;
    
while(t!=cookie)
    
{
        cout
<<"Moving from "<<s1<<" to "<<s2<<"";
        
if(abs(s1-cookie)==abs(s2-cookie)) cout<<"same."<<endl;
        
else if(abs(s1-cookie)>abs(s2-cookie)) cout<<"warmer."<<endl;
        
else if(abs(s1-cookie)<abs(s2-cookie)) cout<<"colder."<<endl;
        cin
>>t;
        s1
=s2;
        s2
=t;
    }

    cout
<<"Moving from "<<s1<<" to "<<s2<<": found it!"<<endl<<endl;
}


int main()
{
//    freopen("fjnu_1298.in","r",stdin);
    cin>>cookie;
    
while(cookie!=5280)
    
{
        find();
        cin
>>cookie;
    }

    
return 0;
}




 
 
资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在 IT 领域,文档格式转换是常见需求,尤其在处理多种文件类型时。本文将聚焦于利用 Java 技术栈,尤其是 Apache POI 和 iTextPDF 库,实现 doc、xls(涵盖 Excel 2003 及 Excel 2007+)以及 txt、图片等格式文件向 PDF 的转换,并实现在线浏览功能。 先从 Apache POI 说起,它是一个强大的 Java 库,专注于处理 Microsoft Office 格式文件,比如 doc 和 xls。Apache POI 提供了 HSSF 和 XSSF 两个 API,其中 HSSF 用于读写老版本的 BIFF8 格式(Excel 97-2003),XSSF 则针对新的 XML 格式(Excel 2007+)。这两个 API 均具备读取和写入工作表、单元格、公式、样式等功能。读取 Excel 文件时,可通过创建 HSSFWorkbook 或 XSSFWorkbook 对象来打开相应格式的文件,进而遍历工作簿中的每个 Sheet,获取行和列数据。写入 Excel 文件时,创建新的 Workbook 对象,添加 Sheet、Row 和 Cell,即可构建新 Excel 文件。 再看 iTextPDF,它是一个用于生成和修改 PDF 文档的 Java 库,拥有丰富的 API。创建 PDF 文档时,借助 Document 对象,可定义页面尺寸、边距等属性来定制 PDF 外观。添加内容方面,可使用 Paragraph、List、Table 等元素将文本、列表和表格加入 PDF,图片可通过 Image 类加载插入。iTextPDF 支持多种字体和样式,可设置文本颜色、大小、样式等。此外,iTextPDF 的 TextRenderer 类能将 HTML、
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值