CW - Compressed Words
Compressed Words
Description
Helen has come up with a way to shorten the length of the messages send to their counter parts in the past. Helen considers only individual words, and uses the following rules to define a "shortened word":
- a single, lower-case letter is a compressed word
- (e1 e2 ... et n) where t and n are non-negative integers and ei is a compressed word.
You should observe that a compressed word of one character is the same as an uncompressed word. To uncompress the compressed word (e1 e2 ... et n) we uncompress each ei , concatenate those uncompressed words into a new word, and repeatedly concatenate that word n times. For example:
- a would be uncompressed as a,
- (a 3) would be uncompressed as aaa,
- (a (b c d 2) 3) would be uncompressed as abcdbcdabcdbcdabcdbcd.
Write a program to uncompress a compressed word.
Input:
The input consists of one correctly formed compressed word of different lengths on a separate line. Every compressed word in the input is correct according to the rules specified above. Letters and numbers are separated from each other by one space character. Brackets and numbers or letters are separated from each other by at least one space character. One bracket is separated from another by one space character.
Output:
For each test case (each compressed word), write the uncompressed word should be displayed on a new line. There should be no spaces in the output.
Input 1:
a
Input 2:
( a 3 )
Input 2:
( a ( b c d 2 ) 3 )
Output 1:
a
Output 2:
aaa
Output 3:
abcdbcdabcdbcdabcdbcd
hide comments
|
mce coders:
2014-03-26 16:15:07
I think problem is still solvable....but yes psetter should allow all languages
|
|
Bhavik:
2014-03-26 15:36:44
i am ok with francky's suggestion..let us wait for one week and then see what happens |
|
Bhavik:
2014-03-26 12:26:24
though it truly deserves to be in classical,but due to the ignorance of psetter all the efforts of users trying to do this is wasted:( i think spoj administrators should take away problem making rights from such people who don't care to make right problems or if psetter have some time issues they should atleast say so that we can look for problem after some time again..
|
|
anurag garg:
2014-03-26 10:57:28
certainly not a tutorial stuff...
|
|
Bhavik:
2014-03-26 08:41:02
@skt: look out for REGULAR EXPRESSIONS..can't give you spoilers though |
|
skt:
2014-03-24 22:27:21
@Bhavik: am getting WAs repeatedly but can't make out what's going wrong. Can I have a few test cases please for the edge cases? |
|
anurag garg:
2014-03-24 14:08:27
easy to implement with c++ |
|
Bhavik:
2014-03-23 11:43:52
any tricky cases??
|
|
Francky:
2014-03-17 13:29:29
Constraints have to be fully given.
|
|
newbie:
2014-03-17 13:29:29
@problem Setter: M getting wrong ans...can u point out if my approach is correct |
Added by: | Arjun Krishnan |
Date: | 2014-03-16 |
Time limit: | 3s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ASM32-GCC MAWK BC C-CLANG C NCSHARP CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM OBJC OBJC-CLANG OCT PHP PICO PROLOG PYTHON PYPY PYPY3 R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET |