c++_湊算式(最新方法)


湊算式ios

B DEF
A + --- + ------- = 10
C GHI

(若是顯示有問題,能夠參見【圖1.jpg】)


這個算式中A~I表明1~9的數字,不一樣的字母表明不一樣的數字。spa

好比:
6+8/3+952/714 就是一種解法,
5+3/1+972/486 是另外一種解法。code

這個算式一共有多少種解法?blog

注意:你提交應該是個整數,不要填寫任何多餘的內容或說明性文字。it

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n[9];
    int count=0;
    for(int i=0;i<9;i++){
        n[i]=i+1;
    }
    do{
        int a=n[0];
        int b=n[1];
        int c=n[2];
        int def=n[3]*100+n[4]*10+n[5];
        int ghi=n[6]*100+n[7]*10+n[8];
        if((b*ghi+c*def)==(10-a)*(c*ghi)){
            count++;
        }
    }while(next_permutation(n,n+9));
    cout<<count;
    
}
相關文章
相關標籤/搜索