full array of violence

Mr. Yang played a game for the students, asking them to use multiplication and subtraction to represent a number. He gave everyone 9 cards, and then reported a number, and asked everyone to express the number in the form of an expression.
100 can be expressed like this Form: 100 = 129*67-8543, can also be expressed as: 100 = 13*489-6257
Note: In the expression, the numbers 1~9 appear respectively and only once (excluding 0).
For expressions like this, 100 has 20 representations.
Question requirements:
Read a positive integer N (N<1000 * 1000) from the standard input, and the
program outputs all the numbers composed of the numbers 1~9 without repetition and omission.
Note: It is not required to output every representation, only count how many representations there are!

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0,s[9]={1,2,3,4,5,6,7,8,9},a,b,c;
    cin>>n;
    do{
        for(int i=0;i<=8;i++)
           {
            a=a*10+s[i];b=0;
            for(int j=i+1;j<=8;j++){
                b=b*10+s[j];c=0;
                for(int k=j+1;k<=8;k++)
                    c=c*10+s[k];
                if(a*b-c==n) 
                {
                    //printf("%d*%d-%d==%d\n",a,b,c,n);
                    cnt++;
                }
            }
        }
        a=b=c=0;
    }while(next_permutation(s,s+9));//全排列
    cout<<cnt;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325258769&siteId=291194637