10019 - Funny Encryption Method

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

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

Post by tan_Yui » Wed Jun 01, 2005 4:42 am

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

Post by asif_rahman0 » Wed Jun 01, 2005 7:45 pm

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! :roll:

Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman » Wed Jun 01, 2005 8:06 pm

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.

User avatar
jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz » Sun Jun 12, 2005 8:15 pm

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)

Post by SiLwS » Wed May 03, 2006 8:23 pm

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 ?

:wink:

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

Post by jan_holmes » Wed May 03, 2006 8:38 pm

just use :

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

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

Hoe it helps... :D

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

Post by emotional blind » Wed May 03, 2006 8:43 pm

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.

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

Ctrl+Z won't work in dev cpp

Post by SiLwS » Wed May 03, 2006 8:45 pm

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

Post by SiLwS » Wed May 03, 2006 8:50 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... :/

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

Post by emotional blind » Wed May 03, 2006 8:59 pm

Dont worry about

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

Post by SiLwS » Wed May 03, 2006 9:07 pm

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

Thank you all ;)

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

Post by emotional blind » Wed May 03, 2006 9:43 pm

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
Location: Edmonton AB Canada

Post by Quantris » Wed May 03, 2006 10:23 pm

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

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

Post by emotional blind » Wed May 03, 2006 10:40 pm

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 :roll:

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko » Thu May 04, 2006 1:06 am

You seem to have a habit of disabling links by putting them into code tags. Why?

Post Reply

Return to “Volume 100 (10000-10099)”