Argo 的个人资料Argo照片日志列表更多 工具 帮助
2007/1/19

小小算法,技术多多

最近写了两个算法。废话少说,开门见山。
 
1、以单词为单位颠倒字符串。
 
问题简单的不能再简单了,网上一搜也是一大把。但是看起来好像都是抄袭的,而且C#版的几乎没有。汗!!!
 
还是自己写一个吧,思路如下:
  1. 翻转整个句子。
  2. 分割空格找到单词,再翻转单词。

  #region ReverseWork
  static string ReverseWord(string statement)
  {
   char[] chs = statement.ToCharArray();
   ReverseWord(chs, 0, chs.Length);

   int i = 0;
   int j = 0;

   while (j < chs.Length)
   {
    if (chs[j] == ' ')
    {
     ReverseWord(chs, i, j - i);
     i = j + 1;
    }
    j++;
   }

   return new string(chs);
  }

  static void ReverseWord(char[] chs, int index, int length)
  {
   int i = index;
   int j = index + length -1;
   while (i < j)
   {
    char ct = chs[i];
    chs[i] = chs[j];
    chs[j] = ct;

    i++;
    j--;
   }
  }
  #endregion

2、将数字字符串转化为整形。如将“123”转化成123数字。

  #region StringToInt
  static void StringToInt(string originalString)
  {
   int iResult = 0;

   int num1 = -1;
   while (++num1 < originalString.Length)
   {
    iResult = iResult * 10 + originalString[num1] - '0';
   }

   Console.Write(iResult);
  }
  #endregion

2007/1/4

2007 期待大片

2007 年终于来了,以下是我期待的几部影片。
 
 
1、Transformer(变形金刚-真人版)
 
我看了预告片,片头作的很震撼。呵呵
 
2、地域骑士
 
补充中...
 
3、忍者神龟
 
补充中...
 
4、虎胆龙威4
 
布鲁斯韦斯利,老当益壮阿!
 
5、蜘蛛侠3
 
邪恶的蜘蛛侠看看如何发威!