欢迎访问我的博客 https://javascript.shop

练习题 英文正常语句倒序书写,标点位置不变

原文发布时间为:2009-03-09 —— 来源于本人的百度文章 [由搬家工具导入]

//算法依据:先整句全倒序,然后遇见空格就把前面的单词再倒序。

using System;// "i come from XiaMen. "变成 " XiaMen. from come i "
namespace unname
{
public class Class2
    {
      public static void Main()
      {
          char[] str = " i come from XiaMen. ".ToCharArray();
          char temp;
          int i = 0, j = str.Length - 1;
          while (i < j)
          {
              temp = str[i];
              str[i] = str[j];
              str[j] = temp;
              i++;
              j--;
          }
          i = 0;
          for (int k = 0; k < str.Length; k++)
          {
              if (str[k] == ' ')
              {
                  j = k - 1;
                  while (i < j)
                  {
                      temp = str[i];
                      str[i] = str[j];
                      str[j] = temp;
                      i++;
                      j--;
                  }
                  i = k + 1;
              }
          }
          Console.WriteLine(str);
          Console.ReadLine();

      }

    }
}

posted @ 2017-07-12 00:05  孑孓子  阅读(99)  评论(0编辑  收藏  举报
欢迎访问我的博客 https://javascript.shop