当前位置:网站首页>Niuke real problem programming - Day9
Niuke real problem programming - Day9
2022-07-07 14:52:00 【weixin_ forty-five million seven hundred and fifty thousand fou】
Compile environment :c++
1、 Wechat red packet description
During the Spring Festival, Xiao Ming received many red envelopes using wechat , Very happy . When checking the record of receiving red envelopes, I found , The amount of a red envelope appears more than half of the total number of red envelopes . Please help Xiao Ming find the amount of the red envelope . Write specific algorithm ideas and code implementation , The algorithm is required to be as efficient as possible .
Given an array of red envelopes gifts And its size n , Please return the requested amount of red envelope . If no amount exceeds half of the total , return 0.
Algorithmic thought :
The problem requires the algorithm to be as efficient as possible , Here we define a result structure , Red envelope amount meets 1≤gifti≤100000 Between , So declare an array of structures , Record N The amount and number of red envelopes , Then sort according to the number from small to large , When the largest element >n/2 when , Output the red packet size of this structure ; otherwise , Return to the unsatisfied condition 0.
The code part implements :

2、 Jin Hua Zha
describe :
Two Sohu programmers worked an extra month , It's finally a holiday , So they decided to tie golden flowers for a happy holiday . The rules of the game : common 52 A common card , The face of the card is 2,3,4,5,6,7,8,9,10,J,Q,K,A One of , Increasing size , Four each ; Each person grabs three cards . Two people compare the size of the three cards in their hands , The big man wins . The rules for card types are as follows : 1. Three cards are leopards 2. Three cards are connected into shunzi (A23 Not shunzi ) 3. There are only two pairs of cards Leopard > Shunzi > Pairs > Ordinary brand type When the card type is the same , Compare the value of the card type ( Such as AAA>KKK,QAK>534,QQ2>10104) When both of them have no special card type , Compare the largest of the three cards in turn . The big man wins , If the biggest card is the same , Is the second largest , And so on ( Such as 37K>89Q) If two people have the same face , It's a draw .
Algorithmic thought :
According to the title requirements , Do not list with complex conditions , But for different card types , Assign integer values of different sizes , To compare . First, judge the two input strings , When there is input , Convert the input to a length of 3 Integer array , take JQK Wait for cards to be converted into integer size ; Then judge the card type of the converted integer array , Leopard *100000、 Shunzi *10000、 Pairwise multiplication 1000、 Ordinary brand type is the largest brand *100. Compare the result size of two input strings , Print the corresponding output .
The code part implements :

3、 First repeating character
describe
For a string , Please design an efficient algorithm , Find the first repeated character .
Given a string ( Not all letters )A And its length n. Please return the first repeated character . Ensure that there are duplicate characters in the string , The length of the string is less than or equal to 500.
Algorithmic thought :
Define a result set , Initialize to 0, Represents that this character has not appeared . Traversing every character in a string , When the characters are not out of date , Mark this character as true, When the same character is traversed for the second time , Just return the current character .
The code part implements :

边栏推荐
- 【愚公系列】2022年7月 Go教学课程 005-变量
- 2022年13个UX/UI/UE最佳创意灵感网站
- How bad can a programmer be? Nima, they are all talents
- JS image to Base64
- #yyds干货盘点# 解决名企真题:交叉线
- Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."
- Leetcode one question per day (636. exclusive time of functions)
- Es log error appreciation -- allow delete
- Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验12 RTC实时时钟实验(学习笔记)
猜你喜欢

What is the process of ⼀ objects from loading into JVM to being cleared by GC?

Cocoscreator operates spine for animation fusion

在软件工程领域,搞科研的这十年!

Pytorch model trains practical skills and breaks through the bottleneck of speed

Full details of efficientnet model

Beginner JSP

时空可变形卷积用于压缩视频质量增强(STDF)

What is cloud primordial? This time, I can finally understand!

Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."

电脑Win7系统桌面图标太大怎么调小
随机推荐
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
安恒堡垒机如何启用Radius双因素/双因子(2FA)身份认证
PG basics -- Logical Structure Management (locking mechanism -- table lock)
Substance Painter笔记:多显示器且多分辨率显示器时的设置
【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
Lidar knowledge drops
激光雷达lidar知识点滴
Classification of regression tests
JSON parsing instance (QT including source code)
Five pain points for big companies to open source
比尔·盖茨晒48年前简历:“没你们的好看”
Today's sleep quality record 78 points
解析PHP跳出循环的方法以及continue、break、exit的区别介绍
EMQX 5.0 发布:单集群支持 1 亿 MQTT 连接的开源物联网消息服务器
PG基础篇--逻辑结构管理(锁机制--表锁)
ES日志报错赏析-maximum shards open
Jetson AGX Orin CANFD 使用
Discussion on CPU and chiplet Technology
Promoted to P8 successfully in the first half of the year, and bought a villa!
Yyds dry goods inventory # solve the real problem of famous enterprises: cross line