## 10019 - Funny Encryption Method

Moderator: Board moderators

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

### 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.

asif_rahman0
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!

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.

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland
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
keep it real!

SiLwS
New poster
Posts: 6
Joined: Wed May 03, 2006 8:12 pm

### 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 ?

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:
just use :

while (scanf("%d",&n) != EOF) {
/*process*/
}

if u want to type an input for EOF,just use ctrl+z

Hoe it helps...

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Contact:
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

Welcome here as a new member.

SiLwS
New poster
Posts: 6
Joined: Wed May 03, 2006 8:12 pm

### 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

SiLwS
New poster
Posts: 6
Joined: Wed May 03, 2006 8:12 pm
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... :/

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Contact:

Code: Select all

^Z
Some compiler shows this characters when u presses

Code: Select all

Ctrl + Z
It just shows you that EOF character is taken.

SiLwS
New poster
Posts: 6
Joined: Wed May 03, 2006 8:12 pm

### LOL

I've been all day looking @ ^Z and never tried to press ENTER ... bah ... a total waste of time ...

Thank you all

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Contact:
Last edited by emotional blind on Thu May 04, 2006 8:38 pm, edited 1 time in total.

Quantris
Learning poster
Posts: 80
Joined: Sat Dec 27, 2003 4:49 am
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).

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am