zoukankan      html  css  js  c++  java
  • 除法

    题意:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果。

    如果没有找到则输出“There are no solutions for N.”。这里2<=n<=79。

    样例输入: 62

    样例输出:

    79546/01238=62

    94736/01528=62

    暴力也要注意技巧啊 。。。

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 const int maxn=10;
     5 
     6 int check(int abcde,int fghij){
     7     int a[maxn]={0};
     8     if(fghij<10000) a[0]=1;
     9 
    10     while(abcde){
    11         int d=abcde%10;
    12         if(a[d]) return 0;
    13         a[d]=1;
    14         abcde/=10;
    15     }
    16     while(fghij){
    17         int f=fghij%10;
    18         if(a[f]) return 0;
    19         a[f]=1;
    20         fghij/=10;
    21     }
    22     return 1;
    23 }
    24 
    25 int main(){
    26     int n;
    27     cin>>n;
    28     int end=98765/n;
    29     int cnt=0;
    30     for( int i=1234; i<=end; i++ ){
    31         int k=i*n;
    32         if(k>=12345&&check(k,i)){
    33             printf("%05d / %05d = %d
    ",k,i,n);
    34         }
    35         cnt++;
    36     }
    37     if(cnt==0){
    38         printf("There are no solutions for %d.
    ",n);
    39     }
    40     return 0;
    41 }
    有些目标看似很遥远,但只要付出足够多的努力,这一切总有可能实现!
  • 相关阅读:
    s111 stark组件
    数据结构
    django基础
    15个值得开发人员关注的jQuery开发技巧和心得
    关于浏览器事件的思考
    关于浏览器事件的思考
    浅入javascript正则表达式的规则.
    JQuery常用功能的性能优化
    vim
    常用免费的WebService列表
  • 原文地址:https://www.cnblogs.com/Bravewtz/p/10346931.html
Copyright © 2011-2022 走看看