zoukankan      html  css  js  c++  java
  • 第六届蓝桥杯省赛---三羊献瑞

    观察下面的加法算式:

    祥 瑞生 辉

    +

    三羊 献 瑞

    =

    三 羊 生 瑞 气  

    其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容。

    分析:这个题目就是单纯暴力就可以,另一个就是想到全排列next_permutation就可以了

     1 #include<iostream>
     2     #include<algorithm>
     3     using namespace std;
     4 
     5     const int maxn = 10;
     6     int main(){
     7         int num[maxn]={0};
     8         for( int i=0; i<maxn; i++ ){
     9             num[i]=i;
    10         }
    11         do{/*全排列后选用2~9这八个数作为选中的值*/
    12             if(!num[2]||!num[6]) continue;
    13             int x=num[2]*1000+num[3]*100+num[4]*10+num[5];
    14             int y=num[6]*1000+num[7]*100+num[8]*10+num[3];
    15             int z=num[6]*10000+num[7]*1000+num[4]*100+num[3]*10+num[9];
    16             if(x+y==z) printf("%d + %d = %d
    ",x,y,z);
    17         }while(next_permutation(num,num+maxn));
    18 
    19         return 0;    
    20     }
    有些目标看似很遥远,但只要付出足够多的努力,这一切总有可能实现!
  • 相关阅读:
    jq---方法总结
    Coderfroces 862 B . Mahmoud and Ehab and the bipartiteness
    Coin
    joisino's travel
    日天的终生大事(dp)
    Codefroces 852 G. Bathroom terminal
    Codefroces432 div2 A,B,C
    Atcoder ABC 069 C
    Codefroces 849 A,B
    HDU 6186 CS Course
  • 原文地址:https://www.cnblogs.com/Bravewtz/p/10391610.html
Copyright © 2011-2022 走看看