当前位置:网站首页>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!”
边栏推荐
- Tensorflow and torch code verify whether CUDA is successfully installed
- R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
- 业务与应用同步发展:应用现代化的策略建议
- 黑馬--Redis篇
- Digital "new" operation and maintenance of energy industry
- [depth first search] Ji suanke: a joke of replacement
- R语言ggplot2可视化时间序列柱形图:通过双色渐变配色颜色主题可视化时间序列柱形图
- Black Horse - - Redis Chapter
- Reptiles have a good time. Are you full? These three bottom lines must not be touched!
- Lucun smart sprint technology innovation board: annual revenue of 400million, proposed to raise 700million
猜你喜欢
Unlock 2 live broadcast themes in advance! Today, I will teach you how to complete software package integration Issues 29-30
第五期个人能力认证考核通过名单公布
Implementation of AVL tree
关于静态类型、动态类型、id、instancetype
Based on butterfly species recognition
Three years of Android development, Android interview experience and real questions sorting of eight major manufacturers during the 2022 epidemic
AutoCAD - what is the default lineweight for centerline drawing and CAD? Can I modify it?
Computer network: sorting out common network interview questions (I)
黑马--Redis篇
如何提高网站权重
随机推荐
Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
If you have any problems, you can contact me. A rookie ~
[depth first search] Ji suanke: Square
Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
Don't miss this underestimated movie because of controversy!
驼峰式与下划线命名规则(Camel case With hungarian notation)
Multithreading Basics: basic concepts of threads and creation of threads
Simple understanding of MySQL database
Implementation of AVL tree
QLabel 跑马灯文字显示
A wearable arm device for night and sleeveless blood pressure measurement [translation]
AutoCAD - what is the default lineweight for centerline drawing and CAD? Can I modify it?
Use map function and split function to type multiple elements in one line
Countdown 2 days | live broadcast preview of Tencent cloud message queue data import platform
ModuleNotFoundError: No module named ‘PIL‘解决方法
Detailed idea and code implementation of infix expression to suffix expression
MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
上海部分招工市場對新冠陽性康複者拒絕招錄
抽象类与抽象方法
Understanding disentangling in β- VAE paper reading notes