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

  • 相关阅读:
    写程序一定要养成良好习惯程序编码规范
    今天用GRID感觉它严重缺少灵活性
    REPEATER 嵌套
    DATAGRID的困惑。。。
    VB常用函数。。。。
    子父表,就是这么简单。。。。。
    今天解决了DataGrid无刷新全选删除问题。
    看来我还没完全懂DATAGRID。。。
    indexOf 和 lastIndexOf 使用
    javascript 要注意的事项
  • 原文地址:https://www.cnblogs.com/zhangruiyuan/p/5295643.html
Copyright © 2011-2022 走看看