• 除法


    题意:输入正整数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 }
    有些目标看似很遥远,但只要付出足够多的努力,这一切总有可能实现!
  • 相关阅读:
    分布式事物的解决方法
    bootstrap的其他
    bootstrap表单控件
    多线程编程
    内存管理技术
    PrintWriter用法简析
    JSP内置对象
    Servlet学习应该注意的几点
    GPU渲染管线概述
    再说AutoComplete
  • 原文地址:https://www.cnblogs.com/Bravewtz/p/10346931.html
Copyright © 2020-2023  润新知