Sphere Online Judge

SPOJ Problem Set (classical)

1163. Java vs C ++

Problem code: JAVAC


Apologists of Java and C++ can argue for hours proving each other that their programming language is the best one. Java people will tell that their programs are clearer and less prone to errors, while C++ people will laugh at their inability to instantiate an array of generics or tell them that their programs are slow and have long source code.


Another issue that Java and C++ people could never agree on is identifier naming. In Java a multiword identifier is constructed in the following manner: the first word is written starting from the small letter, and the following ones are written starting from the capital letter, no separators are used. All other letters are small. Examples of a Java identifier are javaIdentifier, longAndMnemonicIdentifier, name, nEERC.


Unlike them, C++ people use only small letters in their identifiers. To separate words they use underscore character ‘_’. Examples of C++ identifiers are c_identifier, long_and_mnemonic_identifier, name (you see that when there is just one word Java and C++ people agree), n_e_e_r_c.


You are writing a translator that is intended to translate C++ programs to Java and vice versa. Of course, identifiers in the translated program must be formatted due to its language rules — otherwise people will never like your translator.


The first thing you would like to write is an identifier translation routine. Given an identifier, it would detect whether it is Java identifier or C++ identifier and translate it to another dialect. If it is neither, then your routine should report an error. Translation must preserve the order of words and must only change the case of letters and/or add/remove underscores.


Input

The input file consists of several lines that contains an identifier. It consists of letters of the English alphabet and underscores. Its length does not exceed 100.


Output

If the input identifier is Java identifier, output its C++ version. If it is C++ identifier, output its Java version. If it is none, output 'Error!' instead.


Example

Input:
long_and_mnemonic_identifier
anotherExample
i
bad_Style

Output:
longAndMnemonicIdentifier
another_example
i
Error!

Added by:Camilo Andrés Varela León
Date:2006-12-14
Time limit:1s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: ERL JS NODEJS PERL 6
Resource:Northeastern Europe 2006

hide comments
2014-04-17 20:25:05 Sayantan Majumdar
C++ and STL(string and vector used in this case) rocks :D time=0.00 s :)

Last edit: 2014-04-17 20:26:54
2014-03-31 06:05:01 Axel Alejandro Gutiérrez Olivo
@Aravindan, check limit cases. Maybe you are doing something like I was.
2014-03-14 18:11:46 Aravindan Chandrasekaran
Getting Correct Answer for all the cases ... Still WA !
2014-03-06 10:23:49 Michael Moerschell
How to end input?

Last edit: 2014-03-19 18:08:24
2014-03-01 07:47:12 Axel Alejandro Gutiérrez Olivo
I'm using C99 Strict and my code runs perfectly on my computer, Ideone, and CompileOnline using Zeref's (2013-06-06 20:59:31) test cases and more. Nevertheless, I'm getting SIGSEGV here. Any ideas?

EDIT: If someone could make use of this, I was restricting my input to 100 chars, but was modifying the same array so when inserting underscores, I'd get an overflow.

Last edit: 2014-03-05 05:34:46
2014-02-28 01:16:19 Diana Gonzalez
I dont know what's wrong with my code. I've tested every possible case you guys posted.
I need your help @numerix!
2014-02-03 20:07:41 Bhavya Budania
Finally AC after 3 WAs..thnx guys for tricky cases..
2014-01-25 06:21:14 mjh
how to end input in python
2014-01-20 12:17:18 Vinay Sharma
HELP. Segmentation Fault !
2014-01-18 10:19:41 Ayush Vatsa
thanks for the test case guys!!got AC in one go
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.