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
  • 相关阅读:
    关于日志造成的频繁的IO
    PHP
    gitignore
    Linux安装gradle
    Ambari和ClouderManager分析对比
    原生hadoop生态系统组件安装文档
    hive的数据类型和数据模型
    hive概述
    使用binlog和canal从mysql实时抽取数据
    canal概述
  • 原文地址:https://www.cnblogs.com/wangxiaoyong/p/9329331.html
Copyright © 2011-2022 走看看