代码如下:
#include <iostream>
using namespace std;
int main()
{
int DT,HZ,PY,TH;
bool flag=false;
for (DT=1; DT<=4&&!flag; ++DT)
{
for (HZ=1; HZ<=4&&!flag; ++HZ)
{
if (DT==HZ)
continue;
else
for (PY=1; PY<=4&&!flag; ++PY)
{
if (PY==DT||PY==HZ)
continue;
else
{
TH=10-DT-PY-HZ;
if (((DT==1)+(HZ==4)+(PY==3))==1&&((HZ==1)+(DT==4)+(PY==2)+(TH==3))==1
&&((HZ==4)+(DT==3))==1 &&((PY==1)+(TH==4)+(HZ==2)+(DT==3))==1)
{
cout<<"洞庭湖第"<<DT<<"名\n洪泽湖第"<<HZ<<"名\n鄱阳湖第"<<PY<<"名\n太湖第"<<TH<<"名\n";
flag=true;
}
}
}
}
}
return 0;
}
原文:http://blog.csdn.net/liuchang54/article/details/44021073