当前位置:网站首页>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!”
边栏推荐
- Simple understanding of MySQL database
- 包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链
- 三年Android开发,2022疫情期间八家大厂的Android面试经历和真题整理
- GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions
- The nearest library of Qinglong panel
- helm部署etcd集群
- Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan
- 史上超级详细,想找工作的你还不看这份资料就晚了
- The second day of rhcsa study
- Computer network: sorting out common network interview questions (I)
猜你喜欢

业务与应用同步发展:应用现代化的策略建议

How to type multiple spaces when editing CSDN articles

Graffiti intelligence is listed on the dual main board in Hong Kong: market value of 11.2 billion Hong Kong, with an annual revenue of 300 million US dollars
![Looting iii[post sequence traversal and backtracking + dynamic planning]](/img/9b/e9eeed138e46afdeed340bf2629ee1.png)
Looting iii[post sequence traversal and backtracking + dynamic planning]

On AAE

Yutai micro rushes to the scientific innovation board: Huawei and Xiaomi fund are shareholders to raise 1.3 billion

朗坤智慧冲刺科创板:年营收4亿 拟募资7亿

Problems encountered in using RT thread component fish

Cereals Mall - Distributed Advanced p129~p339 (end)

ROS custom message publishing subscription example
随机推荐
Implementation of AVL tree
上海部分招工市場對新冠陽性康複者拒絕招錄
R language uses the order function to sort the dataframe data, and descending sorting based on a single field (variable)
short i =1; i=i+1与short i=1; i+=1的区别
R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
tensorflow和torch代码验证cuda是否安装成功
黑马--Redis篇
CCNP Part 11 BGP (III) (essence)
Certains marchés de l'emploi de Shanghai refusent d'embaucher des personnes qui se rétablissent positives à Xinguan
AIRIOT物联网平台赋能集装箱行业构建【焊接工位信息监控系统】
How to improve website weight
Meilu biological IPO was terminated: the annual revenue was 385million, and Chen Lin was the actual controller
Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
RedisSystemException:WRONGTYPE Operation against a key holding the wrong kind of value
业务与应用同步发展:应用现代化的策略建议
Word如何显示修改痕迹
Multithreading Basics: basic concepts of threads and creation of threads
ROS custom message publishing subscription example
Camel case with Hungarian notation
Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting