2012都要学c++

Copyright (c) 2012, 烟台大学计算机学院         
All rights reserved.         
作    者:  刘元龙       
完成日期:2012 年11  月  8日         
版 本 号:v1.0         
输入描述:     学 c
               要 学 c
			   要 学 c
		 + 都  要 学 C
		 = 2   0  1  2
07.问题描述:利用穷举法输出所有的方案       
08.程序输出:穷举法  
#include <iostream>   
using namespace std;  
int main ()  
{  
   double x,y,z,w,count=0;  
    cout<<"方案有:"<<endl;  
    for(x=0;x<=9;x++)  
        for(y=0;y<=9;y++)  
            for(z=0;z<=9;z++)
				for(w=0;w<=9;w++)
                if((w+10*z)+(w+10*z+y*100)+(w+10*z+y*100+x*1000)==2012&&x!=y&&y!=z&&z!=w)  
                {++count;  
                cout<<count<<"都="<<x<<" "<<"要="<<y<<" "<<"学="<<z<<" "<<"c="<<w<<endl;  
                }  
                return 0;  
}  


运行结果:

 

2012都要学c++_第1张图片

你可能感兴趣的:(2012都要学c++)