当前位置:网站首页>Research on balloon problem
Research on balloon problem
2022-06-26 14:09:00 【fe11953264】
subject
Give you a string text, You need to use text To piece together as many words as possible “balloon”( balloon ).
character string text Each letter in can only be used once at most . Please return the maximum number of words you can piece together “balloon”.
About c
Realization of balloon problem
Find the number of each letter in the given string for each target string , Divide the number of letters in the target string by the number of letters in the target string , The last decimal is the number of balloons
Code
#define min(a , b) ((a) < (b) ? (a) : (b))
int maxnumberofballoons( char * text)
{
int cnt[5];
int n = strlen (text);
memset(cnt , 0 , sizeof(int)*5);
for (int i = 0 ; i < n ; i++ )
{
if (text[ i ] == 'b' )
cnt[ 0 ]++;
else if (text[ i ] == 'a' )
cnt[ 1 ]++;
else if (text[ i ] == 'l' )
cnt[ 2 ]++;
else if (text[ i ] == 'o' )
cnt[ 3 ]++;
else if (text[ i ] == 'n' )
cnt[ 4 ]++;
}
cnt[ 2 ] /= 2;
cnt[ 3 ] /=2;
int res = int_max;
for (int i = 0 ; i < 5 ;i++)
res=min( res, cnt[ i ] );
return res;
}
Key code
Find the length of the string strlen(text)
C++ Medium constant INT_MAX and INT_MIN Each represents the maximum 、 Minimum integer , Definition in header file limits.h in .
#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX - 1)
int res = int_max;
memset: The function is to fill a given value in a block of memory , It is the fastest way to clear a large structure or array
memset(cnt , 0 , sizeof(int)*5);
边栏推荐
- Here document interaction free and expect automatic interaction
- Hands on data analysis unit 3 model building and evaluation
- Mongodb series window environment deployment configuration
- Create your own cross domain proxy server
- On insect classes and objects
- ThreadLocal giant pit! Memory leaks are just Pediatrics
- Zero basics of C language lesson 7: break & continue
- [hcsd application development training camp] one line of code second cloud evaluation article - experience from the experiment process
- MySQL configuration improves data insertion efficiency
- Embedded virlog code running process
猜你喜欢

Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital

33、使用RGBD相机进行目标检测和深度信息输出

Installation and uninstallation of MySQL software for windows

ThreadLocal巨坑!内存泄露只是小儿科...

使用 Performance 看看浏览器在做什么

Es sauvegarde et restauration des données par instantané

Teacher Li Hang's new book "machine learning methods" is on the market! Purchase link attached

永远不要使用Redis过期监听实现定时任务!

输入文本自动生成图像,太好玩了!

基于PyTorch的生成对抗网络实战(7)——利用Pytorch搭建SGAN(Semi-Supervised GAN)生成手写数字并分类
随机推荐
What is the use of index aliases in ES
7-3 minimum toll
Mediapipe gestures (hands)
【HCSD应用开发实训营】一行代码秒上云评测文章—实验过程心得
[MySQL from introduction to mastery] [advanced part] (II) representation of MySQL directory structure and tables in the file system
Es snapshot based data backup and restore
团队管理的最关键因素
7-2 the cubic root of a number
[cqoi2015] task query system
8. Ribbon load balancing service call
Wechat applet -picker component is repackaged and the disabled attribute is added -- above
ThreadLocal巨坑!内存泄露只是小儿科...
ThreadLocal giant pit! Memory leaks are just Pediatrics
Is it safe to open a securities account? Is there any danger
去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程
HW蓝队溯源流程详细整理
GC is not used in D
How to check if a text field is empty or not in swift
[node.js] MySQL module
VTK 圆柱体的生成与渲染