zoukankan      html  css  js  c++  java
  • 有趣的数字算法

    输入正整数 n , 按从大到小的顺序输出所有形如 abcde/fghij = n 的表达式,其中a ~ j为0 ~ 9的数字(不可重复)。2 <= n <=79.

    样例输入:
    62

    样例输出:
    79546/01283 = 62
    94736/01528 = 62

    方法:以62为例

    private bool isRepeat(string val)
        {
            bool result = true;
            foreach(char s in val)
            {
                if (new Regex(s.ToString()).Matches(val).Count > 1)
                {
                    result = false;
                    break;
                }
            }
            return result;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            int max = 98765;
            int min = max / 62;
            for (int i = 1234; i < min; i++)
            {
                if ((isRepeat((i * 62).ToString().PadLeft(5, '0') + i.ToString().PadLeft(5, '0'))))
                {
                    Response.Write((62 * i).ToString().PadLeft(5, '0') + "/" + i.ToString().PadLeft(5, '0'));
                    Response.Write("<br />");
                }
            }
        }

  • 相关阅读:
    c#去除List中的重复项
    c#比较两个List相等
    C#笔记
    解决Xcode真机测试时ineligible devices的问题
    unity3d UGUI多语言
    解决ugui中Image使用iTween的ColorTo、ColorFrom等不生效
    Unity3d uGUI适配
    184. 最大数
    187. 加油站
    46. 主元素
  • 原文地址:https://www.cnblogs.com/94cool/p/1792212.html
Copyright © 2011-2022 走看看