CodinGame: Temperatures 反思

本文回顾了 CodinGame 上的 Temperatures 游戏,介绍了如何找出输入数据中最接近零的温度。游戏旨在检验对选择结构、循环和数组的理解,并提供实践匿名函数和函数式编程的机会。挑战涉及将字符串数组转换为整数数组,找到绝对值最小的数。通过逐级解析关卡,作者分享了解决问题的思路和最终解决方案。

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

Temperatures 温度
主界面

WHAT WILL I LEARN? 我能学到什么?
Conditions,Loops,Arrays 选择结构(if 语句)、循环结构(for/ while 语句)、数组

-Solving this puzzle validates(确认) that the loop concept is understood and that you can compare a list of values.
(解决这个难题可以验证你对循环的概念是否理解,你可以通过比较一个列表的变量/值)
-This puzzle is also a playground to experiment the concept of lambdas(λ, 匿名函数) in different programming languages. It’s also an opportunity to discover functional programming.
(它是一个用不同编程语言的实验的游乐场,也是一个发现函数编程的机会)


The Goal
In this exercise, you have to analyze records of temperature to find the closest to zero.
示例

Rules
Write a program that prints the temperature closest to 0 among input data. If two numbers are equally close to zero, positive integer has to be considered closest to zero (for instance, if the temperatures are -5 and 5, then display 5).

原程序

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
int main()
{
    int n; // the number of temperatures to analyse
    cin >> n; cin.ignore();
    string temps; // the n temperatures expressed as integers ranging from -273 to 5526
    getline(cin, temps);

    // Write an action using cout. DON'T FORGET THE "<< endl"
    // To debug: cerr << "Debug messages..." << endl;

    cout << "result" << endl;
}

关卡

关卡

01 Simple test case 简单的考验

Standard Output Stream:

Input messages are n = 5 temps = 1 -2 -8 4 5
output 1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值