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分钟没出来结果。所以不知道理解的对不对还是运行出错了

  • 相关阅读:
    程序数据校验
    修改文件名后,pip命令报错:Fatal error in launcher: Unable to create process using
    算法竞赛平台
    连续子数组的元素之和最大值
    【数学计算】圆周率
    使用DOS命令关闭tomcat端口(其他服务也是可以的)
    微软project文件mpp解析
    关于读取上传文件问题的两个解决办法
    关于office在卸载了某一应用之后无法试图使用的功能所在的网络位置
    关于eclipse的一些问题
  • 原文地址:https://www.cnblogs.com/zhangruiyuan/p/5295643.html
Copyright © 2011-2022 走看看