形如abcde/fghij = n 的表达式(C语言求解)

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

输入:62

输出:79546/01283=62

   94736/01528=62

 1 #include <stdio.h>
 2
 3 int main()
 4 {
 5     int n,x,y,temp;//a[10]={0};
 6     int i,j,flag;
 7     scanf("%d",&n);
 8     for(x=12345;x<=98765;x++)
 9     {
10         int a[10]={0};
11         flag = 1;
12         temp = x;
13
14     //    if(x%n != 0)                    //不用这句数组a要重新全部初始化!
15     //        continue;
16
17         if(x%n== 0)                        //记录y的各个位
18         {
19
20             y = x/n;
21             for(i=4;i>=0;i--)
22             {
23                 a[i] = y%10;
24                 y = y/10;
25             }
26         }
27
28         for(i=9;i>=5;i--)                //记录x的各个位
29         {
30             a[i] = temp%10;
31             temp = temp/10;
32
33         }
34
35         for(i=0;i<9;i++)                //判断有没有重复的
36         {
37             for(j=i+1;j<=9;j++)
38             {
39                 if(a[i] == a[j])
40                 {
41                     flag = 0;
42                     break;
43                 }
44             }
45             if(flag ==0)
46                 break;
47         }
48
49         if(flag==1)                        //打印
50         {
51             for(i=5;i<=9;i++)
52                 printf("%d",a[i]);
53             printf("/");
54             for(i=0;i<5;i++)
55                 printf("%d",a[i]);
56             printf("=%d\n",n);
57         }
58     }
59     return 0;
60 }
时间: 2024-08-06 07:55:53

形如abcde/fghij = n 的表达式(C语言求解)的相关文章

UVA 725 Division ( 找出 abcde / fghij = N的形式—— 暴力枚举 )

Division Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divide

计算四则运算表达式(Java语言实现)

计算四则运算表达式主要是分两步运算  第一步是把 中缀表达式 转换成 后缀表达式.参考大一下期学的 <数据结构与算法分析--C语言描述>3.3.3 教材,完成下列代码: static String mid_to_suf(String str){ Stack<Character> s = new Stack<Character>(); String suf = new String(); HashMap<Character, Integer> map = ne

003-scanf函数使用和表达式-C语言笔记

学习目标 1.[掌握]输入函数scanf的基本使用方法 2.[掌握]输入函数scanf运行原理和缓冲区理解 3.[掌握]算术运算符和算术表达式的使用 4.[了解]数据类型自动转换和强制转换 5.[掌握]赋值运算符和复合赋值运算符 6.[掌握]自增自减运算符的使用注意 7.[掌握]逗号表达式 一.输入函数scanf的基本使用方法 scanf函数的声明在标准输入输出头文件“stdio.h”中,这个函数用于接受键盘输入的内容. 语法:scanf("格式控制字符串",输入项地址列表); 格式控

中缀表达式转后缀表达式c语言实现

1.运行环境:VS2015/Win7 2.头文件: stack.h 1 typedef char ElementType; 2 /* START: */ 3 #ifndef _Stack_h 4 #define _Stack_h 5 6 struct StkNode; 7 typedef struct StkNode *PtrStk; 8 typedef PtrStk Stack; 9 10 int IsEmpty(Stack S); 11 Stack CreateStack(void); 12

UVA725 Division【枚举】

  Division Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where . That is, abcde / fghij = N wher

Uva 除法

输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a~j恰好为数字0-9的一个排列(可以有前导0,) 2<=n<=79 样例输入: 63 样例输出: 79546 / 01283 = 62 94736 / 01528 = 62 思路:枚举fghij,算出abcde,判断每一个都不相等 //用sprintf #include<iostream> #include<algorithm> #include<cstring> #incl

暴力穷举

暴力除法 题目描述 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a~j恰好为数字0~9的一个排列,2<=n<=79 输入 输入包括多行,每行一个正整数n,2<=n<=79 输出 针对每个输入的n,从小到大输出该表达式,若没有表达式可以生成,则不输出. 样例输入 62 样例输出 79546/01283=62 94736/01528=62 #include<iostream> #include<string.h> using

uva 725 Division(除法)暴力法!

uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that t

UVA 725 Division(hash+枚举)

题目大意: 就是说给你一个abcde/fghij = n的表达式,给你一个n,让你求出有多少个这样的式子. 解题思路: 最为简单的枚举了,要注意到我们只需要枚举出来fghij就可以了,因为abcde=fghij*n,这样的话,时间复杂度由10!就 降低到了5!,在枚举结束后,我们只需要判断0-9这些数字是否都出现了且仅出现一次即可.然后对于超过5位的数字,我们 直接break掉. 这道题的输出一定要注意那个前导0,,一开始忘记了,WA了两次,然后果断用setw(5)和setfill('0')给搞