当前位置:网站首页>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;
}
边栏推荐
- C # basic knowledge (2)
- IO flow review
- Es6~es12 knowledge sorting and summary
- How about agricultural futures?
- SDMU OJ#P19. Stock trading
- Pat grade A - 1164 good in C (20 points)
- 2.14 summary
- Can you draw with turtle?
- Blue Bridge Cup -- Mason prime
- How can I get the Commission discount of stock trading account opening? Is it safe to open an account online
猜你喜欢
How to connect a laptop to a projector
2 spark environment setup local
Yyds dry goods inventory [practical] simply encapsulate JS cycle with FP idea~
SDMU OJ#P19. Stock trading
Unsafe and CAS principle
2022.02.13
How to switch between dual graphics cards of notebook computer
Pointer concept & character pointer & pointer array yyds dry inventory
Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
2022 t elevator repair registration examination and the latest analysis of T elevator repair
随机推荐
Blue Bridge Cup -- Mason prime
How to understand the gain bandwidth product operational amplifier gain
Current detection circuit - including op amp current scheme
AST (Abstract Syntax Tree)
Maxwell equation and Euler formula - link
Qtoolbutton - menu and popup mode
Hcip day 12 notes
Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
[note] glide process and source code analysis
The difference between SRAM and DRAM
Es6~es12 knowledge sorting and summary
Teach you how to run two or more MySQL databases at the same time in one system
Live app source code, jump to links outside the station or jump to pages inside the platform
Comparable interface and comparator interface
1 Introduction to spark Foundation
2 spark environment setup local
QT creator source code learning note 05, how does the menu bar realize plug-in?
2/14 (regular expression, sed streaming editor)
Day30-t540-2022-02-14-don't answer by yourself
Hcip day 15 notes