日期:2014-05-18 浏览次数:21022 次
using System;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            long[] num = new long[count];
            for(int i=0;i<count;i++)
                num[i] = long.Parse(Console.ReadLine());
            string result = string.Empty;
            DateTime dt1 = DateTime.Now;
            foreach (long n in num)
                result += ZeroOrOne(n) + " ";
            Console.Write(result.Trim());
        }
        static int ZeroOrOne(long number)
        {
            double d = Math.Sqrt((number<<1) - 1.75) + 0.5;
            if (d - (long)d == 0) return 1;
            return 0;
        }
    }
}
using System;
class Program
{
  static void Main()
  {
    int count = int.Parse(Console.ReadLine());
    long[] num = new long[count];
    for(int i=0; i < count; i++)
    {
      num[i] = long.Parse(Console.ReadLine());
    }
    foreach (long n in num)
    {
      Console.Write(ZeroOrOne(n));
      Console.Write(" ");
    }
  }
  static int ZeroOrOne(long number)
  {
    double d = Math.Sqrt((number<<1) - 1.75) + 0.5;
    return d == (long)d ? 1 : 0;
  }
}
------解决方案--------------------
好像输入的数字一大就超时。小数字没有问题
------解决方案--------------------
这样更简单,没有必要开一个数组保存输入,边输入边输出就可以了:
using System;
class Program
{
  static void Main()
  {
    int count = int.Parse(Console.ReadLine());
    for(int i = 0; i < count; i++)
    {
      Console.Write(ZeroOrOne(long.Parse(Consoleguration::
------解决方案--------------------