当前位置:网站首页>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;
}
边栏推荐
- Loop compensation - explanation and calculation of first-order, second-order and op amp compensation
- Interesting 10 CMD commands
- QT creator source code learning note 05, how does the menu bar realize plug-in?
- Can you draw with turtle?
- Programming language (2)
- Common problems in multi-threaded learning (I) ArrayList under high concurrency and weird hasmap under concurrency
- C summary of knowledge point definitions, summary notes
- [note] glide process and source code analysis
- Actual combat | use composite material 3 in application
- The 2022 global software R & D technology conference was released, and world-class masters such as Turing prize winners attended
猜你喜欢
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Common mode interference of EMC
Actual combat | use composite material 3 in application
Programming language (1)
Weekly leetcode - nc9/nc56/nc89/nc126/nc69/nc120
The difference between SRAM and DRAM
Design of logic level conversion in high speed circuit
How can enterprises and developers take advantage of the explosion of cloud native landing?
The difference between single power amplifier and dual power amplifier
How to understand the gain bandwidth product operational amplifier gain
随机推荐
Live app source code, jump to links outside the station or jump to pages inside the platform
Teach you how to run two or more MySQL databases at the same time in one system
Op amp related - link
Quick one click batch adding video text watermark and modifying video size simple tutorial
FPGA tutorial and Allegro tutorial - link
炒股開戶傭金優惠怎麼才能獲得,網上開戶安全嗎
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!
[Android reverse] use DB browser to view and modify SQLite database (download DB browser installation package | install DB browser tool)
2/14 (regular expression, sed streaming editor)
The reason why the computer runs slowly and how to solve it
pycuda._ driver. LogicError: explicit_ context_ dependent failed: invalid device context - no currently
Errors taken 1 Position1 argument but 2 were given in Mockingbird
[note] IPC traditional interprocess communication and binder interprocess communication principle
What are the common computer problems and solutions
Sort merge sort
Subset enumeration method
How to solve the problem of requiring a password when accessing your network neighborhood on your computer
Label coco format data and format data in the upper left corner and lower right corner are mutually converted
Xiangong intelligent obtained hundreds of millions of yuan of b-round financing to accelerate the process of building non-standard solutions with standardized products
C # basic knowledge (2)