23
2 8 String Based Programming Puzzles Solved: Join us to win Informatics Olympiad to ICPC N.B. Venkateswarlu AITAM, Tekkali

String based programming puzzles solved

Embed Size (px)

Citation preview

Page 1: String based programming puzzles solved

28 String Based Programming Puzzles Solved: Join us to win Informatics Olympiad to ICPC

N.B. VenkateswarluAITAM, Tekkali

Page 2: String based programming puzzles solved

Copyrights©2016Exclusive Rights are with Author.No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by means of electronic, mechanical, photocopying, recording, scanning or otherwise except with the permission of author.

Page 3: String based programming puzzles solved

Dedicated To

Prof. Jagarlamudi Venkata Ramana Garuand

Dr. K. Someswara Rao Garu

Page 4: String based programming puzzles solved

PrefaceMajority of programming competitions, interviews, examinations will be evidently having substantial number of questions that involves strings. This is true with Informatics Olympiad, ICPC, and other challenging competitions.

This book comprises 28 (256) selected questions that are asked in various worldwide programming contests and demands string manipulations. We have supplied solutions along with explanations including program’s working snap shots. Some of the selected problems uses adhoc logic while others uses popular data structures. We have organized the book such that beginning examples are little demanding compared to last examples such that a novice student can start improving his logical and programming abilities in incremental manner by solving illustrated problems. However, we don’t claim that our solutions are always optimal. Also, in reality we don’t want to claim that one problem is difficult and the other is easy as the adhoc logic what we have used may be inferior to others. However, we have thoroughly tested every problem with various test cases. We are of the opinion that the student can explore the possibility of identifying better solution than ours. Some of the problems are having some questions posed by us. We advise the reader to answer them to build their programming abilities.

We have included enough explanation to make the readers understand the adhoc logic which we have employed in solving some of the problems. We have also included figures wherever needed to explain the logic which we have employed in solving the problems. We have given complete details of the method which we have employed to solve a problem such that readers can solve similar problems in an easy manner.

The examples given in this book are borrowed from various programming competitions of various levels high school to college. All the examples discussed here can be grouped as:

Simple String based puzzles solved Pattern Generation & Animation based puzzles solved Little More involved string based puzzles solved Palindrome Related Puzzles Solved Permutation based string puzzles solved Arithmetic’s based string puzzles solved Card and Deck based puzzles Board and block based string puzzles solved Encryption based puzzles solved Dictionary & Editor oriented puzzles solved Miscellaneous & Complex string based puzzles solved

Beginning examples includes generation of various character based patterns. These examples are aimed at enriching reader towards loop (iterative) building abilities. That is, these examples progressively enlightens reader about nested for or while loops. We strongly believe that these examples can be very much useful in introductory level programming oriented courses of any programming language.

This book embodies three to four dozens of puzzles related to security and encryption. We believe these novice examples are very much useful to develop interest to Computer Science

Page 5: String based programming puzzles solved

students on data security. This book also contains many examples related data compression and data coding.

This book contains many examples related to board and maze. By solving these examples, reader gets equipped with use of stack, back tracking, etc. Moreover, this book accommodated many examples that demands practical use trees and their traversals.

Many illustrious examples are solved to let Computer Science students to have practical exposure and introduction to Computer Science theme areas such as DNA matching, tries, dictionaries, plagiarism, web mining, regular expressions, compiler construction, link extraction, editor design, random numbers, virus detection, Geomatics, Geometry, Graphics, Genetic algorithms, number systems, cross words, etc.

All the solutions are given in C programming language. We presume that the reader has exposure to C programming language elements and enough exposure to writing programs. For those people who feel that they only know the language and have not yet developed their logic skills, first we advise them to read the reputed C programming books. Also, illustrates solutions are written such that they can be understood by the readers who does not have sound foundation in C language but are exposed to other programming languages. All the programs are tested and developed under Bloodshed (www.bloodshed.net) Dev C++ integrated development environment (IDE) which uses GCC compiler tool chain.

We believe this book is going to be very useful for those students who are preparing for IOI, ICPC, Challenge24, Microsoft Cup, Aspirations of Infosys, and others. Also, we are of the opinion that this will be very useful for campus recruitment tests (CRT) conducted by Google, Face Book, Amazon, Microsoft, Wipro, Yahoo, etc.

--Author

Page 6: String based programming puzzles solved
Page 7: String based programming puzzles solved

Acknowledgments

I am very much indebted to student’s of current generation, especially students of AITAM. Also, I am thankful to management of AITAM for giving free time for scribbling this horrendous sized book. I do would like to acknowledge the time spent by Dr. Garimella V Saradamba for proof reading the book.

--Author

Page 8: String based programming puzzles solved

Contents

1.Simple String base puzzles solved1. Dedupe 12. Most Popular letter 33. Krunching Strings 44. Exchange the words before and after AND 65. The String Difference 86. Isograms 107. Countdown 138. Shy Tortoise 159. Word Swap 1810. Base Alphabets 2011. Alphabetically Speaking 2312. Common Letters 2413. Weighing Strings 2614. Balanced Words 2815. Name That Number 3116. Telephone Number Helper 3317. Word Shifter 3618. Obedience School 3719. Gone Phishin 4020. Fire! Fire! Fire! 4221. Letter Game 4522. Birds and Shooters 4823. M&M Factory 5024. Squishing the string 5325. Dashes Removal 5526. Family Concepts 5627. Russel Soundex Index 5828. FOO FIGHTER 6229. Multiprocessing output string validity 6330. A String Decompression 6531. Text Compression 682.Pattern Generation & Animation based puzzles solved32. Drawing A 7033. Triangle with a string 7234. Word in a triangle 7335. Word in a triangle 7436. Word As a Triangle 7637. Tent House 7938. Egg Timer 8039. Dressing Up 8140. Trident 8341. Word Diamonds 8542. Consecutive Diamonds 88

Page 9: String based programming puzzles solved

43. Triangles 8944. Tower Building 9145. Diamond inside a box 9346. The Moving X 9547. STOP Figure 9848. Arrows 10149. Square Designs 10850. Target Practice 11151. Bar Chart 11352. Patterns 11453. Vertical Histogram 11654. Divided Fractals 11855. Hilbert Hack 12656. 0123456789 13357. Bit-Block Characters 13758. It’s a plot 13959. Snake 1423. Little More involved string based puzzles solved60. Code finder 14761. Acronyms 14962. Word Construction 15163. WORD Frequency 15364. Word Stats 15765. Word Morphing 16166. Largest Repeating Prefix 16567. String Subsets 16768. Plagiarism 16969. Letter Grade Assignment with Leniency 17270. Journey to Batlantis! 17571. Fishy Business 17872. Shuttle Puzzle 18073. Word Problems 18574. Contact 18875. Too Many Keys 19576. Wheebop! 19977. Fruit Loops 20278. These Aren’t The Droids We’re Looking For 20379. Check-ing Hai-ku 20680. Word Chain 20981. Letter Selection 21282. All the sub-strings of a string 21783. Character Merged Strings 22084. Smallest Substring in alphabetical order 22385. Broken Necklace 22886. Visual Acuity 23387. Back Seat Driver 236

Page 10: String based programming puzzles solved

88. Weighting Strings 23989. Teams 24190. String Transformations 24391. Reversing Words 24492. BigBucksIn 24693. Sentences from parts 24894. Tournament Winner 25095. Fifol's Orders 25396. Who's calling Pete? 25697. Virus Detection 25998. Hangman Judge 26199. Score Update 265100. Win or Lose 268101. The Magic of Words 272102. Greedy Gift Givers 275103. n-strings 277104. Monotony 281105. Garbage In, Garbage Out 283106. Game, Set, Match 2854. Palindrome Related Puzzles Solved107. Palindromes 289108. Longest Palindrome 291109. Palins 293110. Palindrome Compression 296111. A String Manipulation Problem by any Other Name... 298112. Palmost 300113. Aplindrome (aplindro) 3045. Permutations based puzzles solved114. Partial Primes 307115. Commutation 309116. Restrung 312117. Permute Commute 317118. ID Codes 319119. Fifteen 3226. Arithemetics based puzzles solved120. Letter Arithmetic 324121. When in Rome 325122. Censor 329123. Adding Hex Numbers 331124. Spoken Numerals 335125. English to Integer 338126. Spoken Addition 341127. OOPS! 345128. Majoring in Scales 349129. Kibbles 'n' Bits 'n' Bits 'n' Bits 3557. Card and Deck based puzzles

Page 11: String based programming puzzles solved

130. The Psychic Poker Player 360131. Krypton Factor 374132. Sequence Checking 379133. Accordian patience 381134. Miss You! 385135. Pound in the Shuffle 3908. Board and block based puzzles solved136. So, Who Won? 393137. Where's Ali? 395138. SOS 397139. Defense Line 400140. A Planimeter Problem 407141. Find X 412142. Reversi 415143. Window Area 418144. Frame Up 428145. Biggest Barn 435146. Storage Center 440147. Meet in the Middle 444148. Toggle 448149. Allowance or Aquarium? 453150. Nine-Piece Puzzle 461151. Starry Night 469152. Telling Continents Apart

476153. Squareland 479154. Fish Tank 487155. Inspector Doohickey 494156. Cross Words 501157. Population Explosion 507158. Marvelous Mazes 513159. Masterminds 515160. On The Road Again 518161. Alarm Chain 522162. Go For It: Connect 4 525163. Yomoku 529164. Where’s Waldrof? 531165. Word Walk 536166. Walkabout 539167. Life 546168. Scrambled Flavors 550169. Ice Cream Fad (fad) 554170. Ice Cream Grids (rotate) 558171. Smallest Tile 561172. TRIANGLES 564173. Chain Reaction 570

Page 12: String based programming puzzles solved

174. Skewways crosswords 574175. Othello Moving 579176. Scrambling Words 586177. Rock Paper Scissors … Lizard Spock?? 591178. Islands Smaller Than Rhodes 597179. Transformations 601180. Algrbraic Socks 6079. Encryption based puzzle problems solved181. Oh only have Oh's for a 615182. Vicksburg Cipher 616183. Zombie Spellcheck 621184. Zzzyyx or I’m Out 626185. Decoding 632186. What's Cryptanalysis? 634187. CSBAAOERX 637188. What is on the Grille? 640189. Boole Ciphers 645190. Help me read Paul’s messages 649191. Encoding Grid 653192. Decoder 657193. Dynamic Dictionary Coding 659194. Encoder/Decoder for text strings 662195. The Mystical Cereal Box Decoder 668196. Code Decryption 671197. Caesar's Challenge 677198. Super Encryptor 681199. Ring Tone Composing 684200. Pirate Talk 686201. Let's Talk Zombie 688202. Garbled Message 693203.Tongues 695204. Secretly Lost 698205. Nihongo no AI (Japanese Language AI) 700206. Decoder 702207. Autokey Dyvfitrhh 703208. Encoder and Decoder 706209. Key to Success 710210. Password Cracker 714211. Good Passwords 716212. TALES FROM DECRYPTION 719213. BEJMUL (JUMBLE) 728214. Eakspay igpay atinlay? 733215. Decoding ASCII 736216. Professor Morse's Code 739217. Wippi Leaks 743218. Prime Cryptarithm 747

Page 13: String based programming puzzles solved

10. Dictionary & Editor oriented puzzles solved219. Justifying Text 749220. Insert/Delete 752221. The Year of the Missing Semicolons 754222. Pretty-Print Expressions 757223. Pretty-Print Expressions with Error Checking 759224. Quotations Extraction 763225. A Quotation within a Quotation ... within a Quotation 766226. Dictionary 772227. Runny Babbit 777228. Columnar Tabulation. 784229. Searching articles 786230. Formatting with hyphenation 790231. AmeriCanadian 793232. Directory Wild Cards 795233. Whoops 798234. Dictionary 801235. Building Blocks 803236. The Tokenator 807237. Word Counting 810238. Positive Sentences 812239. Vhat's fur Dinner? 813240. Vocal Punctuation 819241. Removal 821242. Primitive Typewriters 822243. Translation 825244. Simple Compliment Convertor 829245. The HBS Language 831246. Year 2000 833247. Poetry 840248. Identify yourself 848249. Rare Order 85111. Miscellaneous & Complex String based puzzles solved 250. The Errant Physicist 853251. Boxes 865252. Balancing chemical equations 869253. Revelation 888254. The Spaghatta Naddle Synthesizer 894255. Dr. Morse's Dragon Parade 898256. The Array Reloaded 90012. Bonus Problems257. Illegal Hawaiian Virus Collection 903258. Hope Chest Gone Bad 908259. Genetic Algorithms 911260. Genetic Sequencing 913261. Secret Judging League 916

Page 14: String based programming puzzles solved

262. Waiting for Change 920263. Crushing Confections 924264. Missionaries and Canniballs 927265. The DNA string. 930266. Tree Recovery 931267. Nasty virus 937268. Numeric Dictionary order 939

Page 15: String based programming puzzles solved