[Leetcode] 824. Goat Latin

matlab goat 工具箱的例子 matlab goat 工具箱的例子,包括大量讲解,读完后基本会用goat遗传算法 立即下载

Description:

A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.

We would like to convert the sentence to "Goat Latin" (a made-up language similar to Pig Latin.)

The rules of Goat Latin are as follows:

  • If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end of the word.
    For example, the word 'apple' becomes 'applema'.
     
  • If a word begins with a consonant (i.e. not a vowel), remove the first letter and append it to the end, then add "ma".
    For example, the word "goat" becomes "oatgma".
     
  • Add one letter 'a' to the end of each word per its word index in the sentence, starting with 1.
    For example, the first word gets "a" added to the end, the second word gets "aa" added to the end and so on.

Return the final sentence representing the conversion from S to Goat Latin. 

Example 1:

Input: "I speak Goat Latin"
Output: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"

Example 2:

Input: "The quick brown fox jumped over the lazy dog"
Output: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"

Notes:

  • S contains only uppercase, lowercase and spaces. Exactly one space between each word.
  • 1 <= S.length <= 150.

class Solution {
    public String toGoatLatin(String S) {
        String[] a = S.split("\\s");
        String result = "";
        for (int i = 0; i < a.length; i++) {
            char b = a[i].charAt(0);
            String aa = "a";
            for (int j = 0; j < i; j++) {
                aa = aa + "a";
            }
            if (b == 'a' || b == 'e' || b == 'i' || b == 'o'
               || b == 'u' || b == 'A' || b == 'E' || b == 'I' || b == 'O'
               || b == 'U') {
            a[i] = a[i] + "ma" + aa;
            }else {
            a[i] = a[i].substring(1, a[i].length()) + b + "ma" + aa;    
            }
        }
        for (int i = 0; i < a.length; i++) {
            result = result + a[i] + " ";
        }
        return result.substring(0,result.length()-1);
    }
}

 

这里用到了去除string 开头以及结尾的函数:

去开头:a.substring(1,a.length());

去结尾:a.substring(0,a.length()-1);

遗传算法工具箱的注释 遗传算法工具箱的注释,该文档对遗传算法工具箱goat进行了详细注释,方便大家学习 立即下载

相关推荐

matlab环境下的goat遗传算法工具箱-详细注释

matlab环境下的goat遗传算法工具箱-详细注释+使用例子+使用说明,使用更方便,便于学习掌握遗传算法

LeetCode 824. 山羊拉丁文题解

824. 山羊拉丁文 题目来源:824. 山羊拉丁文 2022.04.21 每日一题

小明不要写Bug的博客 241

京瓷扫描驱动安装_京瓷喷头拆解和供墨原理剖析

在工业喷头打印领域,京瓷喷头作为主流喷头广泛应用于喷墨行业,目前京瓷喷头市面上销售主要有两个系列:KJ4A和KJ4B。其中KJ4A系列设计是用于油性墨水,例如UV墨水,主要用在广告领域;而KJ4B设计用于水性墨水,例如活性、分散墨水等,主要用在数码印花领域。最近我们团队对京瓷喷头进行了拆解分析,本期和大家分享一下我们对京瓷喷头拆解和喷头供墨原理的研究。京瓷喷头介绍1. KJ4A系列(油性)如下图所...

weixin_39883906的博客 1677

[leetcode] 824. Goat Latin

题目:A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.We would like to convert the sentence to "Goat Latin" (a made-up language si...

jing16337305的博客 401

Matlab信号处理——基于BP神经网络的调制信号分类与识别

如果你想要进一步了解更多的相关知识,可以关注下面公众号联系~会不定期发布相关设计内容包括但不限于如下内容:信号处理、通信仿真、算法设计、matlab appdesigner,gui设计、simulink仿真......希望能帮到你!对信号进行采样和处理,得到了一系列特征参数,包括幅度均值、频率峰值、频率平方均值以及相位标准差、修正后的相位标准差。

小嘤熊的博客 1309

【HDR】曝光融合(Exposure Fusion)

在曝光融合(Exposure Fusion)算法问世之前,多曝光序列合成用于显示的HDR需要两个步骤,第一步是将多张不同曝光的低动态范围图像合成为HDR(例如Debevec提出的加权融合方法),通常HDR为12bit或者16bit;第二步是通过tonemapping对高动态范围HDR进行压缩以支持低动态范围显示设备(例如Durand提出的基于双边滤波的tonemapping算法),一般会压缩至8bit。

专注人工智能,主攻CV 1万+

LeetCode 824 Goat Latin

LeetCode 824 Goat Latin 传送门 题目分析 A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sen...

博客 1154

Creo报错代码-9?手把手教你重新生成许可证文件(基于Creo 10.0)

本文详细解析Creo报错代码-9的成因及解决方案,重点介绍如何重新生成许可证文件以应对网络环境变化导致的验证失败。通过分步指南和高级技巧,帮助用户有效管理多网络环境下的Creo许可证问题,提升工作效率。

weixin_30839881的博客 565

leetcode 824. Goat Latin

leetcode 824. Goat Latin 原题地址:https://leetcode.com/problems/goat-latin/ 题目 A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters on...

birdreamer的博客 619

逆向工程实战:解密AppleAccount的X-MMe-Nas-Qualify签名生成机制

本文通过逆向工程实战,详细解析了AppleAccount服务中X-MMe-Nas-Qualify签名的生成机制。作者利用Frida进行动态追踪定位签名源头,结合IDA Pro进行静态分析,并借助LLDB动态调试还原核心算法。文章最终分享了如何独立于苹果官方库,通过Python代码复现签名算法,为自动化测试和深度交互苹果服务的开发者提供了关键技术路径。

weixin_29323049的博客 709

双有源桥变换器(DAB)TPS控制:从理论建模到Simulink/PSIM仿真实践

本文深入探讨了双有源桥变换器(DAB)的三重移相(TPS)控制技术,从理论建模到仿真实现。文章详细分析了TPS相比SPS和DPS的优势,阐述了其12种工况的划分逻辑与电流应力最优调制策略,并提供了在Simulink和PSIM平台搭建仿真模型的详细步骤与实战经验,帮助工程师掌握这一高效控制方法。

white的博客 585

LeetCode 824. 山羊拉丁文

随机一题给定一个由空格分割单词的句子 S。每个单词只包含大写或小写字母。我们要将句子转换为 “Goat Latin”(一种类似于 猪拉丁文 - Pig Latin 的虚构语言)。山羊拉丁文的规则如下:如果单词以元音开头(a, e, i, o, u),在单词后添加"ma"。例如,单词"apple"变为"applema"。如果单词以辅音字母开头(即非元音字母),移除第一个字符并将它放到末尾,之后再添加...

菜鸟程序猿的博客 1074

FLUKA软件在Ubuntu的安装指南(亲测有效)

FLUKA其强大的蒙特卡洛模拟能力使得用户能够模拟复杂的辐射相互作用过程

chencheng1127的博客 2888

Leetcode学习笔记:#824. Goat Latin

Leetcode学习笔记:#824. Goat Latin A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to “Goat L...

ccystewart的博客 308

使用Python爬虫抓取政府网站政务信息:公告、通知的自动化抓取与分析

通过结合Requests、BeautifulSoup、Selenium等技术,你能够高效地抓取政府网站的数据,并通过MySQL存储与Pandas分析这些数据。通过自动化手段抓取这些信息,不仅可以提高数据收集的效率,还能够实时获取最新的政务动态,为政策研究、舆情分析等提供宝贵数据。我们将通过Python的Requests、BeautifulSoup、Selenium等工具,结合最新的技术实现一个完整的爬虫系统,帮助你轻松抓取并分析政务信息。通过爬虫,我们可以自动化地从指定网站上抓取公告、新闻、通知等信息。

2201_76125261的博客 1907

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

LeetCode //C - 824. Goat Latin

This problem converts a given English sentence into Goat Latin by applying specific transformation rules to each word. The solution processes each word by checking if it starts with a vowel or consonant, then appends "ma" and adds 'a's based on t

Made in Code 1038

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

LeetCode 824. Goat Latin

题目链接:https://leetcode.com/problems/goat-latin/description/ A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to...

ZayneHuang的博客 276

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

LeetCode刷题记录7——824. Goat Latin(easy)

LeetCode刷题记录7——824. Goat Latin(easy) 目录 LeetCode刷题记录7——824. Goat Latin(easy) 题目 语言 思路 后记 题目 题目需要将一个输入的字符串转化为Goat Latin——山羊拉丁语,有三种转化规则: 如果单词的第一个字符是元音字母(aeiou或者AEIOU),那么保留这个单词的原本格式,并在最后加上ma...

Jmuyjl 693

python leetcode 824. Goat Latin

A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.We would like to convert the sentence to "Goat Latin" (a made-up language simil...

DreamerLHQ的博客 990

[leetcode]824. Goat Latin

[leetcode]824. Goat Latin Analysis 周一快乐~—— [ummm~] A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to...

weixin_32135877的博客 148

LeetCode 824 Goat Latin 解题报告

题目要求 A sentenceSis given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin"(a made-up langua...

weixin_30312563的博客 151

【Leetcode】824. Goat Latin

题目地址: https://leetcode.com/problems/goat-latin/ 给定一个英文字符串,由单词和单词之间的空格构成,要求将每个单词按如下规则做出改变: 1、如果其以元音开头(aeiouAEIOUaeiouAEIOUaeiouAEIOU),则将其后面加上mamama; 2、如果不以元音开头,则将第一个字母置于最后,其后面加上mamama; 3、执行完上面的操作之后,第几个单词就后面跟几个aaa(从111开始计数)。 返回结果。 代码如下: public class Solution

数学、算法爱好者的博客 271
上一篇: [Leetcode] 292. Nim Game
下一篇: [Leetcode] 226. Invert Binary Tree
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值