zoukankan      html  css  js  c++  java
  • LeetCode 题解之Goat Latin

    1、问题描述

    2、问题分析

    将句子拆分成单词,然后放入vector中,对每一个单词做改变,最后连成句子返回。

    3、代码

     1 string toGoatLatin(string S) {
     2         vector<string> words;
     3         for(string::iterator it = S.begin() ; it != S.end(); ++it ){
     4             string::iterator it_i = it ;
     5             while( it_i != S.end() && isalpha( *it_i) ){
     6                 ++it_i ;
     7             }
     8             string word(it,it_i);
     9             words.push_back( word );
    10             if( it_i != S.end() ){
    11                 it = it_i;
    12             }else{
    13                 it = it_i -1 ;
    14             }
    15         }
    16         
    17         string result ;
    18         string a = "a";
    19         set<string> vowels{"a","e","i","o","u","A","E","I","O","U"};
    20         for( auto &s : words ){
    21             if( vowels.find( s.substr(0,1) ) != vowels.end() ){
    22                 s += "ma";
    23             }else{
    24                 s += s[0];
    25                 s.erase( s.begin() );
    26                 s += "ma";
    27             }
    28             s += a;
    29             a += "a";
    30             result += s += " ";
    31         }
    32         
    33         result.erase( result.end() - 1);
    34         return result ;
    35         
    36         
    37     }
    pp
  • 相关阅读:
    java 使用相对路径读取文件
    appium 使用过程问题踩坑-笔记
    CentOS下启动Tomcat
    jodis遇到的问题
    CentOS 7.0 防火墙
    sentinel
    keepalived
    在Tomat7上使用Redis保存Session
    Log4j 使用
    java路径问题
  • 原文地址:https://www.cnblogs.com/wangxiaoyong/p/9329331.html
Copyright © 2011-2022 走看看