当前位置:网站首页>D26: the nearest number (translation + solution)
D26: the nearest number (translation + solution)
2022-07-03 23:14:00 【Aggressive Wenwen】
The original title is :OpenJudge - 26:The Nearest Number
translate :
describe : Given a N Sequence sum of numbers K. Find the sequence with the lowest subscript and K Nearest (X-K The absolute value of is the smallest ) Number of numbers X;
Input : first line : Two positive integers N、K(N<=100、K<=100000);
Output : An integer X.
Code :
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
int a,i,mina,minc=100000;
for(i=1;i<=n;i++){
cin>>a;
if(abs(a-k)<minc){
mina=a;
minc=abs(a-k);
}
}
cout<<mina;
return 0;
}边栏推荐
- Get current JVM data
- Selenium check box
- Pointer concept & character pointer & pointer array yyds dry inventory
- Maxwell equation and Euler formula - link
- How to solve the problem of requiring a password when accessing your network neighborhood on your computer
- The difference between SRAM and DRAM
- 股票开户最低佣金炒股开户免费,网上开户安全吗
- 6.2 normalization 6.2.5 third normal form (3NF)
- URLEncoder. Encode and urldecoder Decode processing URL
- Why should enterprises do more application activities?
猜你喜欢

Teach you how to run two or more MySQL databases at the same time in one system

2/14 (regular expression, sed streaming editor)

Overview of Yunxi database executor

How can enterprises and developers take advantage of the explosion of cloud native landing?

IDENTITY

Programming language (1)

Pyqt5 sensitive word detection tool production, operator's Gospel

Blue Bridge Cup -- Mason prime

Opengauss database log management guide

X Opencv feature point detection and matching
随机推荐
Pointer concept & character pointer & pointer array yyds dry inventory
Design of logic level conversion in high speed circuit
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
In VS_ In 2019, scanf and other functions are used to prompt the error of unsafe functions
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
Sword finger offer day 4 (Sword finger offer 03. duplicate numbers in the array, sword finger offer 53 - I. find the number I in the sorted array, and the missing numbers in sword finger offer 53 - ii
How to write a good title of 10w+?
C # basic knowledge (1)
The difference between SRAM and DRAM
Hcip day 15 notes
Learning methods of zynq
Opengauss database log management guide
Blue Bridge Cup -- Mason prime
Esp-idf turns off serial port log output.
Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
How can I get the Commission discount of stock trading account opening? Is it safe to open an account online
How about opening an account at Hengtai securities? Is it safe?
Es6~es12 knowledge sorting and summary
Shiftvit uses the precision of swing transformer to outperform the speed of RESNET, and discusses that the success of Vit does not lie in attention!
Minimum commission for stock account opening. Stock account opening is free. Is online account opening safe