原文发布时间为: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();
}
}
}