当前位置:网站首页>Translation D28 (with AC code POJ 26:the nearest number)
Translation D28 (with AC code POJ 26:the nearest number)
2022-07-06 19:16:00 【Ctrl AC】
“ Ctrl AC! Together AC!”
The original title is :The Nearest Number
My translation :
describe
Given N Sequence and number of numbers K. stay (X subtract K) Find the nearest number in the sequence with the smallest absolute value of X.
Input
first line : Two positive integers N(N<=100) and K(K<=100000). The second line :N A positive integer (<=100000).
Output
An integer X.
AC Code :
include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;cin>>n>>k;
int minn=0x3f3f3f3f;
int ans=-1;
for(int i=0;i<n;i++){
int num;cin>>num;
if(abs(num-k)<minn){
ans=num;
minn=abs(num-k);
}
}
cout<<ans<<endl;
return 0;
}Thank you for reading !!!
“ Ctrl AC! Together AC!”
边栏推荐
- Installation and management procedures
- short i =1; i=i+1与short i=1; i+=1的区别
- Digital "new" operation and maintenance of energy industry
- Reptiles have a good time. Are you full? These three bottom lines must not be touched!
- QPushButton绑定快捷键的注意事项
- 如何提高网站权重
- Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
- PMP practice once a day | don't get lost in the exam -7.6
- Modulenotfounderror: no module named 'PIL' solution
- 裕太微冲刺科创板:拟募资13亿 华为与小米基金是股东
猜你喜欢

Dark horse -- redis

关于静态类型、动态类型、id、instancetype

Abstract classes and abstract methods

Based on butterfly species recognition

An error occurs when installing MySQL: could not create or access the registry key needed for the

Characteristic colleges and universities, jointly build Netease Industrial College

助力安全人才专业素养提升 | 个人能力认证考核第一阶段圆满结束!

五金机电行业智能供应链管理系统解决方案:数智化供应链为传统产业“造新血”

三面蚂蚁金服成功拿到offer,Android开发社招面试经验

AutoCAD - what is the default lineweight for centerline drawing and CAD? Can I modify it?
随机推荐
五金机电行业智能供应链管理系统解决方案:数智化供应链为传统产业“造新血”
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
安装Mysql报错:Could not create or access the registry key needed for the...
R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
Interface test tool - postman
Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan
R language ggplot2 visual time series histogram: visual time series histogram through two-color gradient color matching color theme
Don't miss this underestimated movie because of controversy!
Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry
数学知识——高斯消元(初等行变换解方程组)代码实现
Based on butterfly species recognition
Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
Analysis of frequent chain breaks in applications using Druid connection pools
[paper notes] transunet: transformers make strongencoders for medical image segmentation
About static type, dynamic type, ID, instancetype
Looting iii[post sequence traversal and backtracking + dynamic planning]
[depth first search] Ji suanke: find numbers
Detailed idea and code implementation of infix expression to suffix expression
English topic assignment (25)