Pefect cubes

I'm doing this problem:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3304

I am getting an excessive output error by the online judge, anyone have any hints they could give me?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    #include <iostream>
    int main()
{
    int a,b,c,d,e,f,g,x;
    for(x = 1; x <= 200; x++)
    {
        a = x * x * x;
 
    for(e = 2; e < x; e++)
    {
        b = e * e * e;
 
    for(f = e; f < x; f++)
    {
        c = f * f * f;

 
    for(g = f; g < x; g++)
    {
        d = g * g * g;
   
  
    if(a == ( b + c + d ))
        std::cout << "Cube = " << x <<"," <<" "<< "Triple = "<<"("<< e << "," << f << "," << g <<")"<< std::endl;
		

    }}}}
    return 0;
}
My guess is that different combinations of the same permutation are being displayed. Check your code with their sample situation. If you change line 5 to for( x = 1; x <= 24; ++x) do you get the same output as them?
This comment is not very helpful, but it seems to me that all the on-line problems are not as trivial as they may first seem. They often involve clever ways of dealing with large numbers or culling lots of output to achieve the short execution times. They are very strict with the required output - 1 extra / missing char somewhere, and it fails - even though the data itself is correct.

So if you have come up with simple code as you have done, then there is probably more to it than you thought.

But good on you for giving it a go - these things are often quite challenging, and you will be a better programmer if you stick with it.

Hope all goes well :+)
@Matt2234

I tried out your program, and it worked great. I then changed variables a, b,c and d, from an int to double when I used a = pow(x,3), since I got the warning,
1>Perfect Cubes.cpp(11): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
. Warnings went away.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Perfect Cubes.cpp : main project file.

#include <iostream>

int main()
{
	bool newline = false;
	
	for(int x = 1; x <= 200; x++)
	{
		double a = pow(x,3);

		for(int e = 2; e < x; e++)
		{
			double b = pow(e,3);

			for(int f = e; f < x; f++)
			{
				double c = pow(f,3);
				
				for(int g = f; g < x; g++)
				{
					double d = pow(g,3);

					if(a == ( b + c + d ))
					{
						std::cout << "Cube = ";
						if(x < 10) // Just to line up the numbers 1 - 200
							std::cout << " ";
						if(x<100)
							std::cout << " ";
						std::cout << x <<"," <<" "<< "Triple = "<<"("<< e << "," << f << "," << g <<")" << std::endl;
					}
				}
			}
		}
	}
	return 0;
}
Topic archived. No new replies allowed.