首页 > 代码库 > HDOJ 2010

HDOJ 2010

//多次测试,发现原因是reNo,reSp如果不在循环体中初始化为0,多次输入数据会错误。//解决方法一如下。二直接把reNo,reSp的定义放在while里面#include "stdio.h"int main(void){	int m, n;	int bw, sw, gw;	int reNo = 0;	 //判断是否输出no	int reSp = 0;	//判断输出空格 		while(scanf("%d%d", &m, &n) != EOF){				while(m <= n){			bw = m / 100;			sw = (m - bw * 100) / 10;			gw = m % 10;							if(m == bw*bw*bw + sw*sw*sw + gw*gw*gw){				if(reSp)					printf(" ");				printf("%d", m);			//printf("%d ", m); Compilation Error 				reNo = 1;				reSp++; 			}	 			m++;		}				if(reNo == 0)			printf("no");		printf("\n");				reNo = 0;	 		reSp = 0;		}		return 0;} 

 

HDOJ 2010