这道问题有一处需要注意的地方是,输入的两个整数不需要从小到大排列,程序应当能自动提取出两个数之间(包括端点)的所有连续整数。
#include<iostream>
using namespace std;
int main()
{
int low,high;
while(cin>>low>>high)
{
int even=0,odd=0;
if(low<=high)
{
int count=low;
for(int i=0;i<high-low+1;++i)
{
if(count%2==0)
even+=count*count;
else
odd+=count*count*count;
++count;
}
}
else
{
int count=high;
for(int i=0;i<low-high+1;++i)
{
if(count%2==0)
even+=count*count;
else
odd+=count*count*count;
++count;
}
}
cout<<even<<" "<<odd<<endl;
}
return 0;
}