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

边栏推荐
- 关于VS2019C#如何建立登陆界面输入的用户名和密码需与Access数据库的记录相匹配
- National food safety risk assessment center: do not blindly and unilaterally pursue "zero addition" and "pure natural" food
- Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
- Weekly snapshot of substrate technology 20220411
- Logstash excludes specific files or folders from collecting report log data
- Open source 23 things shardingsphere and database mesh have to say
- Cesium realizes satellite orbit detour
- How to improve it electronic equipment performance management
- Qt5 signal and slot mechanism (demonstrate the correlation between the control's own signal and slot function)
- 印象深刻的问题
猜你喜欢

Drawing for example study of flashcc

阿里云刘珅孜:云游戏带来的启发——端上创新

一个机器人位于一个 m x n 网格的左上角 。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角。问总共有多少条不同的路径?【LeetCodeHot100】
锚文本大量丢失的问题

面试半年,上个月成功拿到阿里P7offer,全靠我啃烂了这份2020最新面试题!

Leetcode daily practice (sum of two numbers)
![[Niuke's questions] nowcoder claims to have remembered all Fibonacci numbers between 1 and 100000. To test him, we gave him a random number N and asked him to say the nth Fibonacci number. If the nth](/img/70/fa79ba38e28c41ed28bce2ec73cd79.png)
[Niuke's questions] nowcoder claims to have remembered all Fibonacci numbers between 1 and 100000. To test him, we gave him a random number N and asked him to say the nth Fibonacci number. If the nth

# Cesium实现卫星在轨绕行
P. Simple application of a.r.a method in Siyuan (friendly testing)

Smart wind power | Tupu software digital twin wind turbine equipment, 3D visual intelligent operation and maintenance
随机推荐
Qt5 signal and slot mechanism (demonstrate the correlation between the control's own signal and slot function)
分布式Session解决方案
Sliding window + monotone queue concept and example (p1886 Logu)
10 minutes to master the installation steps of MySQL
鴻蒙發力!HDD杭州站·線下沙龍邀您共建生態
National food safety risk assessment center: do not blindly and unilaterally pursue "zero addition" and "pure natural" food
#yyds干货盘点#简述chromeV8引擎垃圾回收
正则匹配以什么开头、以什么结尾,以非什么开头,以非什么结尾
C语言教师工作量管理系统
Deeply digitise, lead cloud nativity and serve more developers
About how vs2019c # establishes the login interface, the user name and password entered must match the records in the access database
一个机器人位于一个 m x n 网格的左上角 。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角。问总共有多少条不同的路径?【LeetCodeHot100】
Mobile terminal click penetration
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
华为云首次解读云原生2.0十大典型架构,加速构建现代化应用
Source NAT address translation and server mapping web page configuration of firewall Foundation
特殊函数计算器
# Cesium实现卫星在轨绕行
面试半年,上个月成功拿到阿里P7offer,全靠我啃烂了这份2020最新面试题!
域名绑定动态IP最佳实践