UVa 725 Division (Division) __uva

Source: Internet
Author: User

Topic Link: UVa 725

Meaning

Enter a positive integer n that prints all expressions, such as abcde/fghij=n, in a small to large order, where a~j happens to be a permutation of the number 0~9 (can have a leading 0), 2<=n<=79.

Analysis:

Violent enumeration. 5 for loop, then check it out.


CODE:

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <

Algorithm> #include <cmath> using namespace std;

int n, t1, T2, vis[10], bad, a[5], i[5], first=1;
	int main () {#ifdef local freopen ("In.txt", "R", stdin);
Freopen ("OUT.txt", "w", stdout);
		#endif while (CIN >> N) {if (n = 0) break;
		if (a), 0;
		else Putchar (' \ n ');
		int flag = 0;  for (i[0] = 0; I[0] < i[0] + +) {for (i[1] = 0; I[1] < i[1] + +) {for (i[2] = 0; I[2] < 10;
							I[2] + +) {for (i[3] = 0 I[3] < i[3] + +) {for (i[4] = 0; I[4] < i[4] + +) {
							Bad = 0;
									for (int j = 0; J < 5; J +) {for (int k = j + 1; k < 5; k++) {if (i[j] = i[k])
										{bad = 1;
									Break
							} if (bad) break;
							} if (bad) continue;
							memset (Vis, 0, sizeof (VIS)); T1 = I[0] * 10000 + i[1] * 1000 + i[2] * + i[3] * + i[4];
							if (t1%n) continue;
							t2 = t1/n;
								for (int j = 0; J < 5; J +) {a[j] = t2% 10;
								T2/= 10;
								VIS[A[J]] = 1;
							VIS[I[J]] = 1;
							Bad = 0;
									for (int j = 0; J < + j) {if (vis[j] = = 0) {bad = 1;
								Break
							} if (bad) continue;
							printf ("%5d/%05d =%d\n", t1, t1/n, N);
						flag = 1;
	}} if (!flag) printf ("There are no solutions for%d.\n", N);
return 0; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.