zoukankan      html  css  js  c++  java
  • 简单枚举(算法竞赛入门经典)

    原题:

    输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a~j恰为数字0~9的一个排列,2<=n<=79.

    AC代码:

     1 #include<iostream>
     2 using namespace std;
     3 bool test(int i,int j);
     4 int main()
     5 {
     6     int n;
     7     cin>>n;
     8     int k=1234;
     9     while(k<=98765)//首先数字要小于98675
    10     {
    11         int m=k*n;
    12         if(m<=98675)
    13         {
    14            if(test(m,k))
    15         {
    16             if(k<10000)
    17             cout<<m<<'/'<<'0'<<k<<'='<<n<<endl;
    18             else
    19             cout<<m<<'/'<<k<<'='<<n<<endl;
    20 
    21         }
    22         }
    23 
    24         k++;
    25     }
    26 }
    27 bool test(int i,int j)
    28 {
    29     int c[10]={0};
    30     int t,s=0;
    31     while(i)
    32     {
    33         t=i%10;
    34         i/=10;
    35         c[s++]=t;
    36     }
    37     while(j)
    38     {
    39         t=j%10;
    40         j/=10;
    41         c[s++]=t;
    42     }
    43     for(int d=0;d<10;d++)
    44     for(int l=d+1;l<10;l++)
    45     if(c[d]==c[l]) return false ;
    46     return true;
    47 }
  • 相关阅读:
    UVA 1001 Say Cheese
    UVa 821 Page Hopping
    UVA 1569 Multiple
    UVA 1395 Slim Span
    UVA 12219 Common Subexpression Elimination
    UVA 246 10-20-30
    Mysql基本操作
    浅析关键字static
    面试回答技巧
    五个程序员好习惯
  • 原文地址:https://www.cnblogs.com/khbcsu/p/3865384.html
Copyright © 2011-2022 走看看