poj.org怎么用啊?我一直都不懂那个规则,它要怎样才算是输入正确。
#include<iostream>usingnamespacestd;intct(inti){returni*i*i;}intmain(){inta,b,c,d;for...
#include<iostream>
using namespace std;
int ct(int i)
{
return i*i*i;
}
int main()
{
int a,b,c,d;
for(a=1;a<=100;a++)
for(b=1;b<=a;b++)
for(c=1;c<=b;c++)
for(d=1;d<=c;d++)
if(ct(a)==ct(b)+ct(c)+ct(d))
{
cout<<"Cube ="<<a<<","<<"Triple =("<<d<<","<<c<<","<<b<<")"<<endl;
}
return 0;
}
这是1543的那个题目,求高手解答并且告诉我哪里错了,我是可以在编译器输出正确的。
http://poj.org/problem?id=1543 那个网址。 展开
using namespace std;
int ct(int i)
{
return i*i*i;
}
int main()
{
int a,b,c,d;
for(a=1;a<=100;a++)
for(b=1;b<=a;b++)
for(c=1;c<=b;c++)
for(d=1;d<=c;d++)
if(ct(a)==ct(b)+ct(c)+ct(d))
{
cout<<"Cube ="<<a<<","<<"Triple =("<<d<<","<<c<<","<<b<<")"<<endl;
}
return 0;
}
这是1543的那个题目,求高手解答并且告诉我哪里错了,我是可以在编译器输出正确的。
http://poj.org/problem?id=1543 那个网址。 展开
展开全部
请注意一下这句话
The values of b, c, and d should also be listed in non-decreasing order on the line itself. There do exist several values of a which can be produced from multiple distinct sets of b, c, and d triples. In these cases, the triples with the smaller b values should be listed first.
按照b,c,d非降序排列
AC code:
#include <stdio.h>
int main(void){
int n,i,j,k,len;
while(scanf("%d",&len)==1){
for(n=6;n<=len;n++)
for(i=2;i<n;i++)
for(j=i+1;j<n;j++)
for(k=j+1;k<n;k++)
if(n*n*n==i*i*i+j*j*j+k*k*k){
printf("Cube = %d, Triple = (%d,%d,%d)\n",n,i,j,k);
break;
}
}
return 0;
}
The values of b, c, and d should also be listed in non-decreasing order on the line itself. There do exist several values of a which can be produced from multiple distinct sets of b, c, and d triples. In these cases, the triples with the smaller b values should be listed first.
按照b,c,d非降序排列
AC code:
#include <stdio.h>
int main(void){
int n,i,j,k,len;
while(scanf("%d",&len)==1){
for(n=6;n<=len;n++)
for(i=2;i<n;i++)
for(j=i+1;j<n;j++)
for(k=j+1;k<n;k++)
if(n*n*n==i*i*i+j*j*j+k*k*k){
printf("Cube = %d, Triple = (%d,%d,%d)\n",n,i,j,k);
break;
}
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询