当前位置:网站首页>Determine the maximum number of specific words in a string
Determine the maximum number of specific words in a string
2022-06-27 16:48:00 【Daily study of bald girls】
Determine the maximum number of specific words in a string
LeetCode Brush problem Day 3
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”.
Example :
Input :text = “nlaebolko”
Output :1
Input :text = “oollpqwa”
Output :0
Topic link :https://leetcode-cn.com/problems/maximum-number-of-balloons/
stay LeetCode Just submit the core function part of the code .
Ideas :
"balloon" in , character l,o The number of is b,a,n Of 2 times . Statistics b,a,l,o,n After the number of , If it happens 5 individual b,5 individual a,10 individual l,10 individual o,5 individual n, be "balloon" The number of 2.
Short board effect , Take the minimum number of characters as the maximum number that can be output .
for example :b,a,l,o,n There were , Yes 2 individual b,1 individual a,10 individual l,4 individual o,3 individual n.l,o,n Although the number of , but a Only 1 individual , So there's only one ”balloon“, The maximum number is 1.
C Language complete code :
#include<stdio.h>
#include<string.h>
int maxNumberOfBalloons(char * text)
{
int zimu[6]={
0}; // Record text In the character a,b,l,o,n The number of times they appear separately , Initialize to 0
int i;
int length;
int count=0;
length=strlen(text); // Calculation text The length of
for(i=0;i<length;i++)
{
if(text[i]=='a') // Statistical characters a Number of occurrences , Save in zimu[0] in , Similarly, record b,l,o,n The number of
zimu[0]++;
if(text[i]=='b')
zimu[1]++;
if(text[i]=='l')
zimu[2]++;
if(text[i]=='o')
zimu[3]++;
if(text[i]=='n')
zimu[4]++;
}
// Statistics b,a,l,o,n After the number of , Short board effect , Take the minimum number of characters as the maximum number that can be output .
zimu[2]=(zimu[2])/2; //l,o The number of is half of the original
zimu[3]=(zimu[3])/2;
int first=zimu[0]; // Make a The number of is equal to first
for (int j = 0; j < 5; j++)
{
if(first<zimu[j]) // if a The number of characters is less than the number of other characters ,a Is the minimum
first=first;
if(first>=zimu[j])// if a The number of characters is greater than the number of other characters , Make first=zimu[j], The number of other characters is the minimum
first=zimu[j];
}
return first;
}
int main()
{
char number[1005];
scanf("%s",&number);
maxNumberOfBalloons(number);
printf("%d\n", maxNumberOfBalloons(number));
}
Running results :

边栏推荐
- 跨域图像的衡量新方式Style relevance:论文解读和代码实战
- 带你认识图数据库性能和场景测试利器LDBC SNB
- 华为云DevCloud重磅发布四大新能力,创下国内两项第一
- Kubernetes basic self-study series | introduction to ingress API
- NFT dual currency pledge liquidity mining DAPP contract customization
- QT5 之信号与槽机制(信号与槽的基本介绍)
- C language teacher workload management system
- Annual comprehensive analysis of China's audio market in 2022
- 【牛客刷题】NowCoder号称自己已经记住了1-100000之间所有的斐波那契数。 为了考验他,我们随便出一个数n,让他说出第n个斐波那契数。如果第n个斐波那契大于6位则只取后6位。
- Regular matching starts with what, ends with what, starts with what, and ends with what
猜你喜欢

Introduce you to ldbc SNB, a powerful tool for database performance and scenario testing

How to improve it electronic equipment performance management

EMQ 助力青岛研博建设智慧水务平台

3.3 one of the fixed number of cycles

EMQ helps Qingdao Yanbo build a smart water platform

Leetcode daily practice (longest substring without repeated characters)

Mobile terminal click penetration

What is the level 3 password complexity of ISO? How often is it replaced?

模拟进程调度

郎酒两大王牌产品成都联动共振,持续带动光瓶酒消费浪潮
随机推荐
事务的隔离级别详解
LeetCode每日一练(无重复字符的最长子串)
SQL parsing practice of Pisa proxy
利用Redis实现订单30分钟自动取消
Hongmeng makes efforts! HDD Hangzhou station · offline salon invites you to build ecology
Data center table reports realize customized statistics, overtime leave summary record sharing
After the mobile phone, it was reported that Samsung also cut the output of TV and other home appliance product lines
智慧风电 | 图扑软件数字孪生风机设备,3D 可视化智能运维
Slow bear market, bit Store provides stable stacking products to help you cross the bull and bear
The role of the symbol @ in MySQL
实现简单的三D立方体自动旋转
LeetCode每日一练(杨辉三角)
Sliding window + monotone queue concept and example (p1886 Logu)
List转Table
NFT dual currency pledge liquidity mining DAPP contract customization
Oracle概念三
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Open source 23 things shardingsphere and database mesh have to say
About MySQL: the phenomenon and background of the problem
10分钟掌握mysql的安装步骤