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
有