当前位置:网站首页>1704. Determine if the two halves of a string are similar
1704. Determine if the two halves of a string are similar
2022-08-05 15:02:00 【Mr Gao】
1704. 判断字符串的两半是否相似
给你一个偶数长度的字符串 s .将其拆分成长度相同的两半,前一半为 a ,后一半为 b .
两个字符串 相似 的前提是它们都含有相同数目的元音(‘a’,‘e’,‘i’,‘o’,‘u’,‘A’,‘E’,‘I’,‘O’,‘U’).注意,s 可能同时含有大写和小写字母.
如果 a 和 b 相似,返回 true ;否则,返回 false .
示例 1:
输入:s = “book”
输出:true
解释:a = “bo” 且 b = “ok” .a 中有 1 个元音,b 也有 1 个元音.所以,a 和 b 相似.
示例 2:
输入:s = “textbook”
输出:false
解释:a = “text” 且 b = “book” .a 中有 1 个元音,b 中有 2 个元音.因此,a 和 b 不相似.
注意,元音 o 在 b 中出现两次,记为 2 个.
解题代码如下:
bool halvesAreAlike(char * s){
int len=strlen(s);
int count=0;
char sr[10]={
'a','e','i','o','u','A','E','I','O','U'};
int i;
for( i=0;i<len/2;i++){
for(int j=0;j<10;j++){
if(s[i]==sr[j]){
count++;
break;
}
}
}
for(;i<len;i++){
for(int j=0;j<10;j++){
if(s[i]==sr[j]){
count--;
break;
}
}
}
if(count==0){
return true;
}
return false;
}
边栏推荐
- 已经自动续期的理财产品要怎么赎回?
- 观测云产品更新|DCA Web 端上线;新增全局的查看器自动刷新配置;新增全局黑名单功能;新增自定义功能菜单等
- 请指教我想今天开户,可以么?手机开户安全么?
- JS--how to write event-driven
- Deficiency needs attention
- Integration testing of software testing
- OneNote 教程,如何在 OneNote 中插入表格并设置其格式?
- 如何找回u盘里丢失的文件,u盘里的文件丢了怎么找回
- Fundamentals of Probability - 11 - Gaussian Distribution / Normal Distribution
- Snake game on June 1st gift for everyone
猜你喜欢

The Hyper - V virtualization vmware data recovery 】 【 file is missing, virtualization server unavailable data recovery case

基于rt-thread studio的STM32裸机开发第二节补充说明:OLED

To be a famous corporate scientist or to be a tenured professor, this is a question

抖音自媒体账号被限流?这3种方法教你如何鉴别

顺序表(上)

PaddleOCR User Guide

7 RESTful

学习用于视觉跟踪的深度紧凑图像表示Learning a Deep Compact Image Representation for Visual Tracking

HDD Hangzhou Station • ArkUI makes development more flexible

为什么你做自媒体赚不到钱?今天就教你几招
随机推荐
アィシャ / 艾夏
addSrouce(sourceFunction),但是我MysqlSource.build之后没有
sklearn Notes: PCA
playwright录制脚本
Typora过期 报错:This beta version of Typora is expired, please download and install a newer version.
灵活好用的sql monitoring 脚本 part2
2022最新综述 | 面向大规模场景的小目标检测:综述和 benchmark
一篇笔记爆不爆,话题占了爆文的绝大部分,这篇文章教你
概率论基础 - 6 - 切比雪夫不等式
The memory problem is difficult to locate, that's because you don't use ASAN
Redis-缓存穿透、击穿和雪崩
概率论基础 - 10 - 常见概率分布
Fundamentals of Probability Theory - 15 - Gamma Distribution
Deficiency needs attention
如何写出头条号原创爆文?这几招教你拿下
Please advise how to open an account for a straight flush?Is it safe to open an account online?
Spine换装方案解析
【补题日记】[2022杭电暑期多校3]K-Taxi
PaddleOCR User Guide
为什么你做自媒体赚不到钱?今天就教你几招