三角数字问题.cpp
来自「将A、B、C、D、E、F这六个变量排成如图所示的三角形」· C++ 代码 · 共 43 行
CPP
43 行
#include <iostream>
#include <iomanip.h>
#include <stdlib.h>
using namespace std;
//枚举法
int main(int argc, char *argv[])
{
int a,b,c,d,e,f;
for(a=1;a<=6;a++)
{
for(b=1;b<=6;b++)
{
if(a==b) continue;
for(c=1;c<=6;c++)
{
if(a==c ||b==c) continue;
for(d=1;d<=6;d++)
{
if(d==a ||d==b ||d==c) continue;
for(e=1;e<=6;e++)
{
if(e==a||e==b||e==c||e==d) continue;
f=21-(a+b+c+d+e);
if(a+b+c==c+d+e && a+b+c==e+f+a)
{
cout<<"**********************"<<endl
<<setw(6)<<a<<endl
<<setw(4)<<b<<setw(4)<<f<<endl
<<setw(2)<<c<<setw(4)<<d<<setw(4)<<e<<endl;
system("pause");
}
}
}
}
}
}
cout<<"**********************"<<endl;
system("PAUSE");
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?