• leetcode6 Reverse Words in a String 单词取反


       Reverse Words in a String  单词取反

        whowhoha@outlook.com

    Question:

    Given an input string s, reverse the string word by word.

    For example, given s = "the sky is blue", return "blue is sky the".

    void reverseWords(string &s) {

            vector <string>des;

            if(s.empty())

                     return;

            int len = s.size();

            for(int i = 0; i < len; i++){

                     if(s[i] == ' ')

                             continue;

                     string word;

                     while(i < len && s[i] != ' '){

                             word += s[i];

                             i++;

                     }

                     des.push_back(word);

            }

            reverse(des.begin(), des.end());

            if(des.empty())

                     s = "";

            else {

                     s.clear();

                     int j ;

                     for(j = 0; j < des.size() -1; j++){

                             s += des[j];

                             s += ' ';

                     }

                     s += des[j];   

            }

    }

  • 相关阅读:
    gsoap 学习 1-自己定义接口生成头文件
    arcgis for silverlight 鼠标点击地图获取当前经纬度
    远程桌面服务器和本机粘贴板共享
    开源ORM
    Memcached
    Visual Studio一些插件
    asp.net 中的事务
    (转载)轻量级表达式树解析框架Faller
    冒泡排序
    (转)理解POCO
  • 原文地址:https://www.cnblogs.com/whowhoha/p/5743289.html
Copyright © 2020-2023  润新知