当前位置:网站首页>2160. minimum sum of the last four digits after splitting
2160. minimum sum of the last four digits after splitting
2022-06-25 07:50:00 【AlbertOS】
introduce
Here's a four just Integers n u m num num . Please use n u m num num Medium digit , take n u m num num Split into two new integers n e w 1 new1 new1 and n e w 2 new2 new2 .
n e w 1 new1 new1 and n e w 2 new2 new2 You can have Leading 0 , And num in all All digits must be used .
For example , Here you are. num = 2932 , The numbers you have include : Two 2 , One 9 And a 3 . Some of the possibilities [new1, new2] The number pair is [22, 93],[23, 92],[223, 9] and [2, 329] .
Please return what you can get new1 and new2 Of Minimum and .
Example
Input :num = 2932
Output :52
explain : feasible [new1, new2] The number pair is [29, 23] ,[223, 9] wait .
The minimum sum is a number pair [29, 23] And :29 + 23 = 52 .
Input :num = 4009
Output :13
explain : feasible [new1, new2] The number pair is [0, 49] ,[490, 0] wait .
The minimum sum is a number pair [4, 9] And :4 + 9 = 13 .
Answer key
The meaning of this topic will be clear from the examples , Is a four digit positive integer , It means finding the two smallest tens in this integer as the first and second number pairs , All that remains is a bit of both , This is the minimum sum .
The obvious greedy method , We put the current smaller value at a higher level , Store... In an array n u m num num The value of each of the , Then sort in ascending order , Then the minimum sum is 10 ∗ ( d i g [ 0 ] + d i g [ 1 ] ) + ( d i g [ 2 ] + d i g [ 3 ] ) 10 * (dig[0]+dig[1])+(dig[2]+dig[3]) 10∗(dig[0]+dig[1])+(dig[2]+dig[3])
class Solution {
public:
int minimumSum(int num) {
vector<int> digits;
// Store each numeric bit in an array
while (num) {
digits.push_back(num % 10);
num /= 10;
}
// Array ascending sort
sort(digits.begin(), digits.end());
return 10 * (digits[0] + digits[1]) + digits[2] + digits[3];
}
};
边栏推荐
- VectorDraw Web Library 10.10
- 國外LEAD域名郵箱獲取途徑
- Understand the reasons for impedance matching of PCB circuit board 2021-10-07
- [daily training] 207 Class Schedule Card
- OpenCV每日函数 结构分析和形状描述符(8) fitLine函数 拟合直线
- Cglib dynamic proxy
- STL tutorial 4- input / output stream and object serialization
- VOCALOID笔记
- OAuth 2.0一键登录那些事
- Different paths ii[dynamic planning improvement for DFS]
猜你喜欢

Summary of small problems in smartbugs installation

ELK + filebeat日志解析、日志入库优化 、logstash过滤器配置属性
![Insert and sort the linked list [dummy unified operation + broken chain core - passive node]](/img/2a/ccb1145d2b4f9fbd8d0812deace93b.png)
Insert and sort the linked list [dummy unified operation + broken chain core - passive node]

realsense d455 semantic_slam实现语义八叉树建图

剑指 Offer II 027. 回文链表

Requirements for Power PCB circuit board design 2021-11-09

一文了解 | 革兰氏阳性和阴性菌区别,致病差异,针对用药
![Different paths ii[dynamic planning improvement for DFS]](/img/bb/1e1cee22b9de954de242d299a1a0eb.png)
Different paths ii[dynamic planning improvement for DFS]

Modular programming of oled12864 display controlled by single chip microcomputer

Do you know why the PCB produces tin beads? 2021-09-30
随机推荐
ts环境搭建
Pcb|about FPC reinforcement type
Technology blog | how to communicate using SSE
Three years of continuous decline in revenue, Tiandi No. 1 is trapped in vinegar drinks
npm install 报错 : gyp ERR! configure error
STL tutorial 4- input / output stream and object serialization
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
PCB board design - automatic layout 2021-10-15
C Getting Started tutorial
Audio (V) audio feature extraction
Insert and sort the linked list [dummy unified operation + broken chain core - passive node]
SCM Project Training
Cifar-10 dataset application: quick start data enhancement method mixup significantly improves image recognition accuracy
Estimation of dense forest volume based on LIDAR point cloud with few ground points
Share the process requirements for single-layer flexible circuit board
年后求职找B端产品经理?差点把自己坑惨了......
[batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)
Application of point cloud intelligent drawing in intelligent construction site
This article uses pytorch to build Gan model!
Collection of common terms and meanings in forestry investigation based on lidar