zoukankan      html  css  js  c++  java
  • 除法(Division,UVa 725)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/A

    题意:

            输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a~j恰好为数字0~9的一个排列(可以与前导0),2<=n<=79。找出所有满足条件的表达式,若无,则输出“There are no solutions for n.”。不同案例输出用空白行分离。

    案例:

            Sample Input

            61

            62

            0

            Sample Output

            There are no solutions for 61.

     

            79546 / 01283 = 62

            94736 / 01528 = 62

    分析:

           不需要枚举所有排列,只需枚举fghij就可算出abcde,然后判断所有数字是否不同即可。
    源代码:

     1 #include<cstdio>
     2 #include<algorithm>
     3 using namespace std;
     4 int b[10];
     5 int test(int m,int n)
     6 {   int z=0;
     7     if(m>98765) return 0;
     8     b[0]=m/10000;//将参数值的个十百千万位数值传递存于数组b
     9     b[1]=m/1000%10;
    10     b[2]=m/100%10;
    11     b[3]=m/10%10;
    12     b[4]=m%10;
    13     b[5]=n/10000;
    14     b[6]=n/1000%10;
    15     b[7]=n/100%10;
    16     b[8]=n/10%10;
    17     b[9]=n%10;
    18     sort(b,b+10);//数组b进行排序
    19     for(int j=0;j<10;j++)//判断参数值个十百千万位是否符合要求
    20         if(b[j]==j) z++;
    21     if(z==10) return z;//判断参数值是否由0~9构成且不重复
    22     else return 0;
    23 }
    24 int main()
    25 {
    26     int N,i,cnt=0,count;
    27     while(scanf("%d",&N)&&N>=2&&N<=79)
    28     {   
    29         count=0;
    30         if(cnt++) printf("
    ");//格式控制
    31         for(i=1234;i<=98765;i++)
    32             if(test(i*N,i))//测试数据是否符合要求
    33             {  printf("%05d / %05d = %d
    ",i*N,i,N);
    34                ++count;
    35             }
    36         if(count==0)//判断能否产生符合要求的数据 
    37            printf("There are no solutions for %d.
    ",N);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    原生js实现简单的全屏滚动
    原生拖拽js利用localstorage保存位置
    vue组件利用formdata图片预览以及上传
    手机端原生js实现下拉刷新数据
    读啥技术服务支持
    涂鸦壁纸技术服务支持
    JAVA基础面试题
    JAVA编程入门
    DOS常用命令及进制转换
    JS基础(事件的绑定)
  • 原文地址:https://www.cnblogs.com/huaszjh/p/4680981.html
Copyright © 2011-2022 走看看