当前位置:网站首页>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;
}边栏推荐
- NPM script
- Fluent learning (5) GridView
- [issue 16] golang's one-year experience in developing Purdue Technology
- [network security] what is emergency response? What indicators should you pay attention to in emergency response?
- Minimum commission for stock account opening. Stock account opening is free. Is online account opening safe
- Opengauss database log management guide
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
- The difference between SRAM and DRAM
- Learning notes of raspberry pie 4B - IO communication (SPI)
猜你喜欢

Programming language (2)

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

How to prevent malicious crawling of information by one-to-one live broadcast source server

How to solve the problem of requiring a password when accessing your network neighborhood on your computer
![[note] IPC traditional interprocess communication and binder interprocess communication principle](/img/f6/36c28df02198539e27352e3cdf4ba6.jpg)
[note] IPC traditional interprocess communication and binder interprocess communication principle

The difference between SRAM and DRAM

Design of logic level conversion in high speed circuit

Unsafe and CAS principle

How to write a good title of 10w+?

How to switch between dual graphics cards of notebook computer
随机推荐
Is the controller a single instance or multiple instances? How to ensure the safety of concurrency
Xiangong intelligent obtained hundreds of millions of yuan of b-round financing to accelerate the process of building non-standard solutions with standardized products
Unity shader visualizer shader graph
Les sociétés de valeurs mobilières dont la Commission d'ouverture d'un compte d'actions est la plus faible ont ce que tout le monde recommande.
Simple solution of m3u8 file format
How to connect a laptop to a projector
Mongoose the table associated with the primary key, and automatically bring out the data of another table
Live app source code, jump to links outside the station or jump to pages inside the platform
Schematic diagram of crystal oscillator clock and PCB Design Guide
What are the common computer problems and solutions
Hcip day 16 notes
C3p0 connection MySQL 8.0.11 configuration problem
Bufferpool caching mechanism for executing SQL in MySQL
File copy method
In VS_ In 2019, scanf and other functions are used to prompt the error of unsafe functions
How to restore the factory settings of HP computer
Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
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
2.14 summary
Op amp related - link