当前位置:网站首页>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 :

边栏推荐
- 全球首款 RISC-V 笔记本电脑开启预售,专为元宇宙而生!
- ES日志报错赏析-trying to create too many buckets
- 属性关键字OnDelete,Private,ReadOnly,Required
- How does the database perform dynamic custom sorting?
- leetcode:648. Word replacement [dictionary tree board + find the shortest matching prefix among several prefixes]
- Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
- Mlgo: Google AI releases industrial compiler optimized machine learning framework
- ⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
- C 6.0 language specification approved
- 半小时『直播连麦搭建』动手实战,大学生技术岗位简历加分项get!
猜你喜欢

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

什么是云原生?这回终于能搞明白了!

Substance Painter筆記:多顯示器且多分辨率顯示器時的設置

拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条...

Webrtc audio anti weak network technology (Part 1)

Xiaomi's path of chip self-development

Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)

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

Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist

《微信小程序-进阶篇》组件封装-Icon组件的实现(一)
随机推荐
一个程序员的水平能差到什么程度?尼玛,都是人才呀...
Delete a whole page in word
Simple use of websocket
缓冲区溢出保护
JS in the browser Base64, URL, blob mutual conversion
Jetson AGX Orin CANFD 使用
Attribute keywords serveronly, sqlcolumnnumber, sqlcomputecode, sqlcomputed
智汀不用Home Assistant让小米智能家居接入HomeKit
CPU与chiplet技术杂谈
寺岗电子称修改IP简易步骤
Cocoscreator resource encryption and decryption
asp.netNBA信息管理系统VS开发sqlserver数据库web结构c#编程计算机网页源码项目详细设计
半小时『直播连麦搭建』动手实战,大学生技术岗位简历加分项get!
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
Promoted to P8 successfully in the first half of the year, and bought a villa!
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
Mmkv use and principle
用于增强压缩视频质量的可变形卷积密集网络
Notes de l'imprimante substance: paramètres pour les affichages Multi - écrans et multi - Résolutions
Cocos creator direction and angle conversion