Hi all. I was trying a question in SPOJ. Let me explain the question first. The input will be a single line containing capital and small letters. Lets assume the following:
Capital Letters-Opcode
Small Letters-Operands
In AbcdEf,
A is an opcode. The operands of A are b,c and d.
Similarly, E is an opcode and its operands are f. The opcodes must be moved to the closest upper index that is a multiple of 4.
So, AbcD must be Abc-D, where '-' means a blank (output is 1).
Similarly, ABC must be A---B---C, so the output is 6.
Similarly, AbcdeF must be Abcde---F, so the output is 3.
The task is, to find the minimum number of '-'s that are needed to be inserted to align the Opcodes accordingly.
Here is my solution to this task:
RESOLVED
It is 42 chars long and its the second shortest. The first shortest is 39 chars long. Can u pls try to make it shorter?
Edit: http://www.spoj.pl/problems/NOP/
Edit2: Corrected a small typo. (thanks to Ken)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.