Page 2 of 4

Posted: Tue Jun 17, 2003 9:40 am
by globi
Thanks a lot ( I got accepted :) ).

Posted: Wed Jun 25, 2003 2:04 pm
by szymcio2001
Some additional test cases for everyone who has a problem with negative input:
0 -> 0
-1 -> -1
-2 -> -16777217
-65536 -> 65535

Posted: Thu Jul 03, 2003 3:00 pm
by Ronald29
Thx, I already have AC

Posted: Thu Jul 03, 2003 3:00 pm
by Ronald29
Thx, I've already got AC

Posted: Sat Dec 27, 2003 8:36 pm
by aakash_mandhar
Try this code. this is very easy problem
[cpp]
Code removed.
Thx Shamim for the suggestion
[/cpp]

Hope u like the code

Easy sol to endian...

Posted: Sat Dec 27, 2003 8:37 pm
by aakash_mandhar
Removed.. Thx Shamim for the suggestion

594- One Little, Two Little, Three Little Endians WA

Posted: Fri Aug 27, 2004 3:05 pm
by RustB
This is giving me correct answers with my trial inputs, but the judge returns W.A. Why is that?
[c]
#include <stdio.h>

union inp
{
long num;
char a[4];
} in,out;

int main(void)
{
while(!feof(stdin))
{
int i;
in.num=out.num=0;
scanf("%d",&in.num);
for(i=0;i<4;i++)
out.a=in.a[3-i];
printf("%d converts to %d\n",in.num,out.num);
}
}
[/c]

Posted: Fri Sep 03, 2004 4:01 pm
by Ryan Pai
There's probably an end-of-line character at the end of the data. You should always make your solution not depend on there being/not being one.

So after it reads the last number, there's still that last character, the end-of-line. So the feof() returns false. But the next iteration you don't read a number, so it outputs 0.

Also, the endianness of your system might be different than the judges (unless you checked what they use and compared it to what you use).

594 - got WA

Posted: Mon Sep 06, 2004 6:00 pm
by acmforacm
i got WA~
who can help me ?

Code: Select all

#include <stdio.h>
#include <math.h>

main()
{
        long long n , num;
        int i , j , k;
        int binary[4][8];
        while ( scanf ( " %lld" , &n ) == 1 ){
                printf ( "%lld" , n );
                for ( i=0; i<4; ++i )
                        for ( j=0; j<8; ++j )
                                binary[i][j] = 0;
                i = j = num = 0;
                while ( n >= 1 ){
                        binary[i][j++] = n % 2;
                        n /= 2;
                        if ( j == 8 ){
                                j = 0;
                                i++;
                        }
                }
                for ( i=3 , k=0; i>=0; --i , ++k ){
                        for ( j=0; j<8; ++j ){
                                num += binary[i][j] * pow( 2 , ( ( k * 8 ) + j ) );
                        }
                }
                printf ( " converts to %lld\n" , num );
        }
}

Posted: Fri Sep 10, 2004 9:22 pm
by Ghust_omega
Hi acmforacm i found one bug in your code not handlle negative inputs fine see what is the ouput for this
-7 , -5 is 0 you have to check your code
Hope its Helps :)
Keep posting !

AC.

Posted: Wed Jul 05, 2006 11:38 am
by linux
Hey, RustB! Don't be worried about endians they are same as you did. But about end-of-line character ryan pai is right. I think you better use scanf by which I got AC from you program.

594 Problem

Posted: Thu Dec 14, 2006 10:09 am
by B.E
I would just like to say that the problem is very easy(did it in under a minute). The code I used was (which the CPU time was 0.004 seconds) The following. It works by using the 80386 assembly instruction to byte swap an integer (the instruction is often used to convert big endian numbers to little endian numbers and vice versa).

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main(){
	char buff[13];
	register long l;
	while (gets(buff)){
		l = atol(buff);
		__asm__ __volatile__ ("bswap %0" : "+r" (l));
		printf("%s converts to %d\n", buff, l);
	}
	return 0;
}

Posted: Tue Jun 26, 2007 1:00 am
by lovemagic
can somebody explain when the output should be negetive? & how can i handle negetive number?

Posted: Thu Jun 28, 2007 2:15 pm
by Jan
lovemagic wrote:1. can somebody explain when the output should be negetive?
2. how can i handle negetive number?
1. What is the value of binary(1111111...111 -> 32 1's) for a signed 32-bit integer?
2. No special condition I think.

Posted: Thu Jun 28, 2007 5:35 pm
by lovemagic
Thanx for ur reply.Now i understood.
Got AC...... :D