问题及代码:
/*
* Copyright (c) 2016,烟台大学计算机与控制工程学院
* All rights reserved.
* 文件名:renwu.cpp
* 作者: 贾庆严
* 完成日期:2016年3月10日
* 版本号:V1.0
*
* 问题描述:在下面的加法算式中,不同的符号代表不同的数字,相同的符号代表相同的数字。请设计程序求出”都、要、学、C”4个符号分别代表的数字。
* 程序输入:无
* 程序输出:都 要 学 c 的数字
*/
#include <iostream>
using namespace std;
int main()
{
int dou,yao,xue,c,s;
for(dou=1;dou<3;dou++)
for(yao=0;yao<10;yao++)
for(xue=0;xue<10;xue++)
for(c=0;c<10;c++)
{
s=4*c+3*xue*10+2*yao*100+dou*1000;
if(s==2008)
cout<<"都:"<<dou<<" 要:"<<yao<<" 学:"<<xue<<" C:"<<c<<endl;
}
return 0;
}
运算结果: