2005-11-21 13:26
对第一题代码作了一定优化,速度大大提高,但总感觉还会有更好的方法。
[ Last edited by 大花狗上树 on 2005-11-21 at 13:32 ]
代码:
/*******************************/
/* Q:WWWDOT-GOOGLE=DOTCOM */
/* A:777589-188103=589486 */
/* 777589-188106=589483 */
/*******************************/
#include "stdio.h"
#include "conio.h"
void main()
{
int w,d,o,t,c,m,g,l,e;
for (w = 1;w<=9;w++)
for (d = 1;d<=9;d++){
if (w==d) continue;
for (o = 0;o<=9;o++) {
if (o==d||o==w) continue;
for (t = 0;t<=9;t++) {
if (t==d||t==w||t==o) continue;
for (c = 0;c<=9;c++) {
if (c==d||c==w||c==o||c==t) continue;
for (m = 0;m<=9;m++) {
if (m==d||m==w||m==o||m==t||m==c) continue;
for (g = 1;g<=9;g++) {
if (g==d||g==w||g==o||g==t||g==c||g==m) continue;
for (l = 0;l<=9;l++) {
if (l==d||l==w||l==o||l==t||l==c||l==m||l==g) continue;
for (e = 0;e<=9;e++){
if (e==d||e==w||e==o||e==t||e==c||e==m||e==g||e==l) continue;
int google=g*100000+o*10000+o*1000+g*100+l*10+e;
int dotcom=d*100000+o*10000+t*1000+c*100+o*10+m;
int wwwdot=w*100000+w*10000+w*1000+d*100+o*10+t;
if(wwwdot==(google+dotcom)){
printf ("%d%d%d%d%d%d-",w,w,w,d,o,t);
printf ("%d%d%d%d%d%d=",g,o,o,g,l,e);
printf ("%d%d%d%d%d%d\n",d,o,t,c,o,m);
}
}
}
}
}
}
}
}
}
getchar();
}
请小心你的思想,它会影响你的行为,
请小心你的行为,它会影响你的习惯,
请小心你的习惯,它会影响你的性格,
请小心你的性格,它会影响你的命运。
请小心你的行为,它会影响你的习惯,
请小心你的习惯,它会影响你的性格,
请小心你的性格,它会影响你的命运。