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

边栏推荐
- SQL parsing practice of Pisa proxy
- 当发布/订阅模式遇上.NET
- 继手机之后 报道称三星也削减了电视等家电产品线的产量
- Mobile terminal click penetration
- 阿里云刘珅孜:云游戏带来的启发——端上创新
- National food safety risk assessment center: do not blindly and unilaterally pursue "zero addition" and "pure natural" food
- Introduce you to ldbc SNB, a powerful tool for database performance and scenario testing
- ICML 2022 ぷ the latest fedformer of the Dharma Institute of Afghanistan ⻓ surpasses SOTA in the whole process of time series prediction
- Bit. Store: long bear market, stable stacking products may become the main theme
- 锚文本大量丢失的问题
猜你喜欢

Leetcode daily practice (main elements)

开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事

Mobile terminal click penetration

Source NAT address translation and server mapping web page configuration of firewall Foundation

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

字节跳动埋点数据流建设与治理实践

List to table

About MySQL: the phenomenon and background of the problem

Redis系列2:数据持久化提高可用性

事务的四大特性
随机推荐
特殊函数计算器
带你认识图数据库性能和场景测试利器LDBC SNB
【多线程】线程通信调度、等待集 wait() 、notify()
Oracle concept II
What is the level 3 password complexity of ISO? How often is it replaced?
Use redis to automatically cancel orders within 30 minutes
How to improve it electronic equipment performance management
Leetcode daily practice (longest substring without repeated characters)
Julia constructs diagonal matrix
Adaoracle supports multi chain distributed Oracle with wide area node quotation
C语言教师工作量管理系统
C语言课程设计
10 minutes to master the installation steps of MySQL
# Cesium实现卫星在轨绕行
Sliding window + monotone queue concept and example (p1886 Logu)
关于VS2019C#如何建立登陆界面输入的用户名和密码需与Access数据库的记录相匹配
C language teacher workload management system
华为云DevCloud重磅发布四大新能力,创下国内两项第一
锚文本大量丢失的问题
Redis系列2:数据持久化提高可用性