Page 2 of 4
Re: Help me in understanding the prob 10019
Posted: Wed Jun 01, 2005 4:42 am
by tan_Yui
Hi, asif_rahman0. This is one of simple Ad Hoc (maybe Math) Problem.
You task is to find the B1 & B2.
You'll read the input number M.
First of all, X1 = M (decimal) , you have to convert X1 to binary.
Second, X2 = M (hexadecimal) , you have to convert X2 to binary.
Finaly, find B1 (count '1's of X1) and B2 (count '1's of X2).
Let's think following sample.
Input M = 265
X1 = 265 ( = 2*10^2 + 6*10^1 + 5*10^0 )
convert X1 to binary : 100001001
X2 = 613 ( = 2*16^2 + 6*16^1 + 5*16^0 )
convert X2 to binary : 1001100101
count '1's :
B1 = 3, B2 = 5
So, output is 3 5.
Best regards.
Thnaks
Posted: Wed Jun 01, 2005 7:45 pm
by asif_rahman0
Thanks for reply.But still I've a confusion.That is for ur given example:
1)First convert 265(decimal) to binary and count the 1's.
2)Second 613(hex) to binary and this time also count the 1's.
My question is how I get the hex value 613?Is it convert 265 to hex or anything else?But convert 265 to hex the value is 109!

Posted: Wed Jun 01, 2005 8:06 pm
by Mohammad Mahmudur Rahman
No, you won't convert 265 to Hex. Rather, you will consider 265 as a hexadecimal number & convert that into decimal to get 613.->
Posted: Sun Jun 12, 2005 8:15 pm
by jaracz
you can do that as follow:
Code: Select all
scanf("%x",&M); <---- read number in hexdecimal system(i.e. 265)
sprintf(buff,"%d",M); <---- convert this number to decimal(string)
num = atoi(buff); <---- convert string to integer (613)
sprintf(buff,"%x",M); <---- convert number to string(hex)
num2 = atoi(buff); <--- convert string to integer(265)
then you have these 2 numbers, the rest is as simple as this above
Regards
EOF (newbie doubt)
Posted: Wed May 03, 2006 8:23 pm
by SiLwS
I'm a newbie programmer ... I'm still in high school and my knowledge about C is not quite big... I'm not used to the EOF situation ... I'm used to test in console so ... my doubt is... what could be the best way of testing my programs... I usually use dev cpp, and I'm having problems in testing an EOF situation ... Is there any "friendly" solution ?
I'm not used to DOS... neither opening files in C ... and I don't know how to "simulate" an end of file in console... so I'm not able to test that way ... any suggestions ?

Posted: Wed May 03, 2006 8:38 pm
by jan_holmes
just use :
while (scanf("%d",&n) != EOF) {
/*process*/
}
if u want to type an input for EOF,just use ctrl+z
Hoe it helps...

Posted: Wed May 03, 2006 8:43 pm
by emotional blind
There are a lot of threads and posts read those,
and try to solve your problem.
I think youi are new here, you should know that,
it is not reasonable to creat a new thread here if the related thread
already exist there
Welcome here as a new member.
Ctrl+Z won't work in dev cpp
Posted: Wed May 03, 2006 8:45 pm
by SiLwS
I know about ctrl+z ... the problem is that when i type Ctrl+Z it appears something like ^Z and does not simulate the EOF ... I don't know if it is because of keyboard config... (I guess not cause a friend of mine told that he usually uses that and he uses the portuguese config of keyboard like me) ... What prgrm you use to program ?
thanks anyway

Posted: Wed May 03, 2006 8:50 pm
by SiLwS
I didn't found no post about simulating an EOF or how to test it ... that's why I created a new post... as far as I searched I wasn't able to get answer to my problem... If there is actually one I'm sorry for "reposting" it... :/
Posted: Wed May 03, 2006 8:59 pm
by emotional blind
Dont worry about
Some compiler shows this characters when u presses
It just shows you that EOF character is taken.
LOL
Posted: Wed May 03, 2006 9:07 pm
by SiLwS
I've been all day looking @ ^Z and never tried to press ENTER ... bah ... a total waste of time ...
Thank you all

Posted: Wed May 03, 2006 9:43 pm
by emotional blind
Posted: Wed May 03, 2006 10:23 pm
by Quantris
Personally, I prefer redirecting files on the command line, such as:
./program < in.txt > out.txt
... which lets you test how the program handles various cases etc. easily, and also produces an output file for diff'ing with output from somewhere else (like the forum).
Posted: Wed May 03, 2006 10:40 pm
by emotional blind
SiLwS wrote:I didn't found no post
about simulating an EOF or how to test it ... that's why I created a new post... as far as I searched I wasn't able to get answer to my problem... If there is actually one I'm sorry for "reposting" it... :/
What does it means

Posted: Thu May 04, 2006 1:06 am
by Darko
You seem to have a habit of disabling links by putting them into code tags. Why?