这几天也不知道做些什么了,就看看编程爱好者的比赛题目,现在的比赛看不懂都...嘿嘿,从第一界开始洒洒....
昨天做了,第一题把代码搞丢了,今天做了第2题,没想到用了2个小时,调试,运行,反正不管怎么样终于是完成了..
//编程爱好者:第2次编程比赛:
//Make By:qingfeng
//2006.6.5
//输入两个整数(要求100以内的自然数),若这两个整数之间存在自然数对,
//则将其中所有的自然数对输出,否则输出不存在的提示.
//所谓的自然数对是指两个自然数的和与差都是平方数.
//例如:17-8=9,17+8=25,那么17与8就是自然数对!
//例如:输入:2 11
// 输出: 4 5
// 6 10
//****************************************************************
#include <iostream>
#include <cmath>
using namespace std;
void ziran(int c, int d)
{
int temp;
if( c < d)//把较大的数移到前面
{
temp=c;
c=d;
d=temp;
}
int h=c;
int i =d;
for(;d <= h ; d++)
//for(; c > i;c--)
{
c =h;
//d =i;
for(; c > i;c--)
//for(;d <= h ; d++)
{
int e = c - d;
int f = c + d;
if((int)sqrt(e) == sqrt(e) && (int)sqrt(f) == sqrt(f) && e!= 0)//判断
{
if(d > c)
break;
else
cout << d << " " << c << "/n";
}
}
}
}
int main()
{
int a,b;
cout <<"Please input the numer of 1~~100:/n";
cin >> a >> b;//判断是否超出范围
if(a > 100 || a < 0 || b >100 || b < 0)
cout <<"input error,input of 1~100!/n";
else
ziran(a,b);
return 0;
}
把代码贴出来,留个纪念......
当然自己还是菜,只要能做出来就行了,算法了,数据结构了..什么也不会用..嘿嘿...