zoukankan      html  css  js  c++  java
  • 阅读代码

    老师给定代码:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace FindTheNumber
    {
      class Program
      {
        static void Main(string[] args)
        {
          int [] rg = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24,25,26,27,28,29,30,31};
          for (Int64 i = 1; i < Int64.MaxValue; i++)
          {
            int hit = 0;
            int hit1 = -1;
            int hit2 = -1;
            for (int j = 0; (j < rg.Length) && (hit <=2) ; j++)
            {
              if ((i % rg[j]) != 0)
              {
                hit++;
                if (hit == 1)
                {
                  hit1 = j;
                }
                else if (hit == 2)
                {
                  hit2 = j;
                }
                else
                  break;
              }
    
            }
            if ((hit == 2)&& (hit1+1==hit2))
            {
              Console.WriteLine("found {0}", i);
            }
          }
        }
      }
    }

    阅读分析:给定一个30个数字的从2至31的数组,刚开始Int64不太懂什么意思,百度查了下解释

    这样就大致能理解了,通过for循环遍历数组直到结束或hit大于2之前,找到不能被整除i的数,hit就++,hit1和hit2中分别保存的是最后两个不能整除i的数组中的数,如果这两个数相邻则输出i的数值。但是运行程序,等了40分钟没出来结果。所以不知道理解的对不对还是运行出错了

  • 相关阅读:
    遍历一个枚举类型
    ASP.NET:C#中时间格式的转换
    DataAdapter去批量更新数据的FAQ
    .Net/C#: 实现支持断点续传多线程下载的 Http Web 客户端工具类 (第2版) (C# DIY HttpWebClient) 收藏
    如何使数据库中取出的数据保持原有格式
    如何获取控制台应用程序自己的文件名
    2008将倒掉一大部分的工厂和贸易公司
    组六对半分组组合投资方案(36789)
    重又归孑然一身
    善于总结
  • 原文地址:https://www.cnblogs.com/zhangruiyuan/p/5295643.html
Copyright © 2011-2022 走看看