10110 - Light, more light
Moderator: Board moderators
10110....WA
This is one of the easy problem as far as i know........is it really????.....hmmmmm......but it always gives me wrong answer.......why???[c]
#include<stdio.h>
#include<math.h>
main()
{
long n,s;
while(1)
{
scanf("%ld",&n);
if(n==0)
break;
s = (long)sqrt(n);
if(s*s==n)
printf("yes\n");
else
printf("no\n");
}
}[/c]
[/c]
#include<stdio.h>
#include<math.h>
main()
{
long n,s;
while(1)
{
scanf("%ld",&n);
if(n==0)
break;
s = (long)sqrt(n);
if(s*s==n)
printf("yes\n");
else
printf("no\n");
}
}[/c]
[/c]
right you are
Hello Rlatif,
Here is a quote from the problem statement:
Either use unsigned long or long long.
Otherwise your code seems to be correct.

Here is a quote from the problem statement:
long can not handle inputs more that 2^31-1.The input will be an integer indicating the n'th bulb in a corridor. Which is less then or equals 2^32-1.
Either use unsigned long or long long.
Otherwise your code seems to be correct.

10110 light more light runtime error
hi every body,
i thankful if anybody help me to fix this problem
i submitted my code into the judge amd he gave me a runtime error
please help me
[code]
#include <iostream>
using namespace std;
void Switch( int &state )
{
if ( state == 1 )
state = 0;
else
state = 1;
}
int main()
{ int a[10],i=0,j,size;
int bulb;
char *str[2]={ "no","yes"};
char* out[10];
cin >> a[0];
while(a[i]!=0)
{ i++;
cin>>a[i];}
size=i;
i=0;
while ( i != size ) {
bulb=a[i] ;
int state = 0;
for ( j = 1; j <= bulb; j++ )
if ( bulb % j == 0 ) {
Switch( state );
if ( j * j != bulb )
Switch( state );
}
*(out+i)=*(str+state);
i++;
}
for( i=0;i<size;i++)
cout<<out[i]<<endl;
return 0;
}
another question is that how can i get the compiler that the judge use it
can anyone give me a site i can downloaded??
[/code]
i thankful if anybody help me to fix this problem
i submitted my code into the judge amd he gave me a runtime error
please help me
[code]
#include <iostream>
using namespace std;
void Switch( int &state )
{
if ( state == 1 )
state = 0;
else
state = 1;
}
int main()
{ int a[10],i=0,j,size;
int bulb;
char *str[2]={ "no","yes"};
char* out[10];
cin >> a[0];
while(a[i]!=0)
{ i++;
cin>>a[i];}
size=i;
i=0;
while ( i != size ) {
bulb=a[i] ;
int state = 0;
for ( j = 1; j <= bulb; j++ )
if ( bulb % j == 0 ) {
Switch( state );
if ( j * j != bulb )
Switch( state );
}
*(out+i)=*(str+state);
i++;
}
for( i=0;i<size;i++)
cout<<out[i]<<endl;
return 0;
}
another question is that how can i get the compiler that the judge use it
can anyone give me a site i can downloaded??
[/code]
-
- New poster
- Posts: 3
- Joined: Thu Apr 22, 2004 8:12 pm
-
- Learning poster
- Posts: 77
- Joined: Fri Dec 17, 2004 11:06 am
- Location: East West University, Dhaka, Bangladesh
- Contact:
This is my accepted code. Just look... so small and so simpl
This is my accepted code. Just look... so small and so simple. 
I hope, it will inspire you to think in a simple way.

I hope, it will inspire you to think in a simple way.
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
long double num,b;
long a;
while(1)
{
scanf("%Lf",&num);
if(num==0)
break;
a= some_function(num);
//calling a commonly used
//builtin C function.
b= some_function(num);
// same function again.
if(a==b)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/
http://groups.yahoo.com/group/acm_solver/
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
10110 Presentation Error
Hi
I get a PE with this program. Its driving me crazy now. Could some1 plz tell me why i m getting it. Thanks in advance.
I get a PE with this program. Its driving me crazy now. Could some1 plz tell me why i m getting it. Thanks in advance.
Code: Select all
#include <iostream.h>
#include <math.h>
int main()
{
int flag = 1;
unsigned long i;
while (flag)
{
cin >> i;
if (i != 0)
{
double value = i;
double sqrtvalue = sqrt(value);
if (floor(sqrtvalue) - sqrtvalue == 0.00) //perfect square
cout<<"yes\n";
else cout<<"no\n";
}
else flag=0;
}
return (0);
}
Ah....
Well, that's odd..
.. I just submitted your code and got AC without presentation error.
.. I just submitted your code and got AC without presentation error.

Doesnt even Compile!!!
Actually I was trying my code at the Programming Challenges website, where I was repeatedly getting a PE.
After seeing that the code was getting accepted at the online-judge, I did try mailing it. I mailed the following :-
And the program doesn't even compile now!!!!
What has gone wrong? This is the first time I am using the online-judge, so maybe I am doing something that is downright stupid. Could you please point it out, and help me out of this mess.
Thanks
After seeing that the code was getting accepted at the online-judge, I did try mailing it. I mailed the following :-
Code: Select all
/* @JUDGE_ID: 62454TK 10110 C++ */
/* @BEGIN_OF_SOURCE_CODE */
#include <iostream.h>
#include <math.h>
int main()
{
int flag = 1;
unsigned long i;
while (flag)
{
cin >> i;
if (i != 0)
{
double value = i;
double sqrtvalue = sqrt(value);
if (floor(sqrtvalue) - sqrtvalue == 0.00) //perfect square
cout<<"yes\n";
else cout<<"no\n";
}
else flag=0;
}
return (0);
}
/* @END_OF_SOURCE_CODE */
What has gone wrong? This is the first time I am using the online-judge, so maybe I am doing something that is downright stupid. Could you please point it out, and help me out of this mess.
Thanks
10110
I think if the number of bulbs is a perfect square, then answer is yes, otherwise no. Is my guess incorrect?
I get WA every time. Plz anyone tell me whts wrong here?
I have solved the problem.
Code: Select all
deleted
I have solved the problem.
Abhishek Roy
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.