VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > C#教程 >
  • Timus 1001

制作者:剑锋冷月 单位:无忧统计网,www.51stat.net
 

  题目如下:

  

Reverse root
Time Limit 2.0 second
Memory Limit 16 MB
Input The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 1018). The numbers are separated by any number of spaces and line breaks. A size of the input stream does not exceed 256 KB.
Output For each number Ai from the last one till the first one you should output its square root. Each square root should be printed in a separate line with at least four digits after decimal point.

  解决办法有点‘笨’Timus 1001,如下

  C# Codeusing System;

using System.Threading;
using System.Globalization;
namespace Test
{
  class Program
  {
    static void Main(string[] args)
    {
      Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;//这句话必须要,否则提交不过(原因)
      char[] buff = new char[256*1024];
      Console.In.ReadBlock(buff, 0, 256*1024);
      string temp = string.Empty;
      bool first = true;
      for (int i = buff.Length - 1; i >= -1; i--)
      {
        if (i != -1 &&buff[i] != '' && buff[i] != 'r' && buff[i] != 'n'&& buff[i] != 't'&& buff[i] != ' ')
        {
          if (!first)
          {
           temp = string.Empty;
          }
         temp = temp.Insert(0, buff[i].ToString());
         first = true;
       }
  
       else
       {
  
         if (!string.IsNullOrEmpty(temp) &&first)
         {
  
           Console.WriteLine(Math.Sqrt(double.Parse(temp)).ToString("F4"));
         }
         first = false;
       }
     }
   }
  } 
}

  下面这样做当然要简单些了:

  C# Codeusing System;

using System.Threading;
using System.Globalization;
using System.Text.RegularExpressions;
namespace Test
{
  class Program
  {
     static void Main(string[] args)
     {
       Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
       string temp = Console.In.ReadToEnd();
       string[] numbers = new Regex(@"s+", RegexOptions.Compiled).Split( temp );
       if (numbers.Length == 0)
       {
          numbers = new string[] { temp};
       }
       for (int i = numbers.Length - 1; i >= 0; i--)
       {
          if( !string.IsNullOrEmpty( numbers[i] ))
          {
            Console.WriteLine(Math.Sqrt(double.Parse(numbers[i])).ToString("F4"));
          }
       }
     }
  }
}

  可是无论是从时间还是空间上都不如第一种方法,原因我还不大清楚。

  从前两道题我体会最多的是C#的Console原来也有这么多内容,不过说实话,这些东西也没有太多必要去记,要用的时候查一下就可以了,毕竟需要真正记住的东西太多了...



相关教程