zoukankan      html  css  js  c++  java
  • [面试题]翻转字符串中的单词

     1 /// <summary>
     2        /// 翻转字符串中的单词
     3        /// ex.   
     4        ///    I am chinese.   -> I ma esenihc.
     5        /// </summary>
     6        /// <param name="strInput"></param>
     7        /// <returns></returns>

     8        static string ReverseWordInString(string strInput)
     9        {
    10            string strMeta = "";  //不用反的 标点符号
    11            StringBuilder strReturn = new StringBuilder();
    12            Stack<char> stack = new Stack<char>();
    13            foreach (char c in strInput)
    14            {
    15                if (strMeta.IndexOf(c) != -1)
    16                {
    17                    while (stack.Count > 0)
    18                    {
    19                        strReturn.Append((char)stack.Pop());
    20                    }

    21                    strReturn.Append(c);
    22                }

    23                else
    24                    stack.Push(c);
    25            }

    26
    27            return strReturn.ToString();
    28        }
  • 相关阅读:
    & 微信支付对比
    # MySQL性能优化技巧
    & mysql简单定时增量全量备份
    & Mysql高级总结
    python面向对象
    django虚拟环境的安装
    Python 内置函数
    Python列表解析式
    函数练习
    Python装饰器
  • 原文地址:https://www.cnblogs.com/sskset/p/719603.html
Copyright © 2011-2022 走看看