Blue Bridge Cup/C + + band fraction

Source: Internet
Author: User

100 can be expressed as a fractional form: 3+69258/714 or 82+3546/197. Similar to the band score, 100 total 11 kinds of notation. With fractions, the digital 1~9 appear only once (not including 0).

Please write a C + + program, enter a positive integer n (n<1000000), Output n with a digital 1~9 do not omit to make up the total number of fractional representation. For example, enter 100, output 11, and 105, then output 6. Note: It is not required to output each representation, only output all the number of numbers with fractional notation!

#include <iostream>
#include <algorithm>
using namespace Std;
int f (int start, int end,int *arr) {
if (Start > End)
return 1;
int n = 0;
for (int i = start; I <= end; i++) {
n = n * + arr[i];
}
return n;
}
int size (int n) {
int count=0;
while (n) {
count++;
n/= 10;
}
return count;
}
int main () {
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int n, a, b, c,count=0;
CIN >> N;
do{
for (int i = 0; I <= size (n); i++) {
for (int j = i; J < 8; J + +) {
A = f (0, I, arr);
b = f (i + 1, J, arr);
c = f (j + 1, 8, arr);
if (n = = a + b/c && b% c = = 0) {
count++;
cout << a << "+" << B << "/" << c << Endl;
}
}
}
} while (Next_permutation (arr, arr + 9));
cout << Count << Endl;
}

Blue Bridge Cup/C + + band fraction

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.