You are not logged in. Please login at www.codechef.com to post your questions!

×

CHFINT - Editorial

PROBLEM LINK:

Practice

Contest

Author: rahul_ojha_07

DIFFICULTY:

EASY

PREREQUISITES:

Knowledge of Binary numbers

PROBLEM:

Given a Binary String find the corresponding column title as present in an Excel Sheet for the decimal representation of the string.

QUICK EXPLANATION:

Convert The Binary String to corresponding Decimal Number then by taking the modulo of the decimal number we'll convert it to the Alphabetical Excel Column Number.

EXPLANATION:

Firstly we'll convert the Binary String to Decimal Number. Suppose we take an empty string ANS which will contain our answer. Now suppose the Decimal representation of the binary string is K, so corresponding to it we need to print the column name. So we need to take the remainder with 26. If remainder with 26 comes out to be 0 (meaning 26, 52 and so on) then we put ‘Z’ in the answer string and new K becomes K/26 -1 because here we are considering 26 to be ‘Z’ while in actuality it’s 25th with respect to ‘A’. Similarly, if the remainder comes out to be non zero. (like 1, 2, 3 and so on) then we need to just insert the char accordingly in the string and do K = K/26.

Finally, we reverse the string and print it.

EXAMPLE

let us take an example: The string of Binary number be S = 10000000001 (say)

find the corresponding decimal value of S which in this case is 1025, K = 1025 The empty string ANS = " "

taking mod of K with 26 gives a Remainder value of 11 now corresponding Excel column Title for 11 is 'K' now we'll add it to the string ANS. Now ANS="K" and K=K/26 = 39

Now again repeating the same process Remainder = K%26 i.e. Remainder = 13 and corresponding Excel column Title for 13 is 'M', adding it to the String ANS,Now ANS = "KM" and K = K/26 = 39/26 = 1

As K is now less than 26 so we'll directly add the corresponding Excel column Title to the String which is 'A'. So now, ANS="KMA" and K=K/26 = 0. so Reverse of the ANS is our final answer. which is AMK.

Author's solution can be found here.

This question is marked "community wiki".

asked 08 Oct, 18:06

rahul_ojha_07's gravatar image

3★rahul_ojha_07
12
accept rate: 0%

edited 11 Oct, 17:17

admin's gravatar image

0★admin ♦♦
19.5k348496535


I dont know if I am missing something but isn't the constraint on (length of binary string) n <=100000 so how can we convert such a long binary string into decimal that will fit into long long ?

link

answered 08 Oct, 19:35

spam_123's gravatar image

1★spam_123
112
accept rate: 0%

edited 08 Oct, 19:35

You need to use Python or BigInteger class in Java I guess.

(08 Oct, 21:16) horsbug985★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×162
×2

question asked: 08 Oct, 18:06

question was seen: 66 times

last updated: 11 Oct, 17:17