10019 - Funny Encryption Method
Moderator: Board moderators
Re: Help me in understanding the prob 10019
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.
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.
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
Thnaks
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!
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!

-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
No, you won't convert 265 to Hex. Rather, you will consider 265 as a hexadecimal number & convert that into decimal to get 613.->
Code: Select all
613 = 2 * 16^2 + 6 * 16 + 5 * 1.
You should never take more than you give in the circle of life.
you can do that as follow:
then you have these 2 numbers, the rest is as simple as this above
Regards
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)
Regards
keep it real!
EOF (newbie doubt)
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 ?

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 ?

-
- Experienced poster
- Posts: 136
- Joined: Fri Apr 15, 2005 3:47 pm
- Location: Singapore
- Contact:
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Ctrl+Z won't work in dev cpp
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
thanks anyway

-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Dont worry aboutSome compiler shows this characters when u pressesIt just shows you that EOF character is taken.
Code: Select all
^Z
Code: Select all
Ctrl + Z
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Some links of related threads
http://online-judge.uva.es/board/viewtopic.php?t=5430
http://online-judge.uva.es/board/viewtopic.php?t=4768
http://online-judge.uva.es/board/viewtopic.php?t=3377
http://online-judge.uva.es/board/viewtopic.php?t=272
http://online-judge.uva.es/board/viewtopic.php?t=457
What do you mean ENTER works but CTRL+Z doesnt work
^Z shows your input its not output.
http://online-judge.uva.es/board/viewtopic.php?t=5430
http://online-judge.uva.es/board/viewtopic.php?t=4768
http://online-judge.uva.es/board/viewtopic.php?t=3377
http://online-judge.uva.es/board/viewtopic.php?t=272
http://online-judge.uva.es/board/viewtopic.php?t=457
What do you mean ENTER works but CTRL+Z doesnt work
^Z shows your input its not output.
Last edited by emotional blind on Thu May 04, 2006 8:38 pm, edited 1 time in total.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact: