Translator
In a country of Neverland there are two types of programmers, People who
program using a language X(X people) and people who program using a language Y(Y
people).
Both are equally good languages but there is no translator that could
translate X language to Y and vice versa.Apologists of X and Y can argue for hours proving each other that their
programming language is the best one.Y people will tell that their programs are clearer and less prone to errors,
while X 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 X and Y people could never agree on is identifier naming.
In Y 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 Y identifier are
yIdentifier, longAndMnemonicIdentifier, name,nEERC.Unlike them, X people use only small letters in their identifiers. To
separate words they use underscore character "_". Examples of X identifiers are x_identifier, long_and_mnemonic_identifier,
name (you see that when there is just one word X and Y people agree),
n_e_e_r_c.
Your job is to write a translator that is intended to translate programs in X
to Y 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 Y identifier or X 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
N, Number of testcases 0<N<=50
N 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 Y identifier, output its X version. If it is X
identifier, output its Y version. If it is none, output "Error!" instead.
Sample Input:
4
long_and_mnemonic_identifier
anotherExample
i
bad_Style
Sample Output:
longAndMnemonicIdentifier
another_example
i
Error!
import java.io.*; class CharDemo { public static void main(String a[]) throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int test=Integer.parseInt(in.readLine()); String input[]=new String[test]; for(int i=0;i<test;i++) { input[i]=in.readLine(); } String output[]=new String[test]; for(int k=0;k<test;k++) { int m=0; char[] arr=input[k].toCharArray(); char temp[]=new char[arr.length+6]; for(int i=0;i<arr.length;i++) { if(Character.isUpperCase(arr[i])&&i!=0) { temp[m++]='_'; temp[m++]=Character.toLowerCase(arr[i]); } else if(arr[i]=='_') { if(Character.isLowerCase(arr[i+1])) temp[m++]=Character.toUpperCase(arr[++i]); else { m=0; for(int f=0;f<"Error!".length();f++) temp[m++]="Error!".charAt(f); i=arr.length+2; } } else temp[m++]=arr[i]; } output[k]=new String(temp); } for(int k=0;k<test;k++) System.out.println(output[k]); } }
These loans are uncertain in nature and in the short term, because they offer the amount from £ 100 up to £ 1,000 for a limited period, 14-31 days bad credit loans. The plus point of this aid is rare on security against the crowd payday loans no credit check. Another plus point is that you can extend the time to pay a symbolic fee for the creditor. To do this, you can avoid unwanted. The interest rate charged is higher than regular loans payday loans lenders. This may be different from the less efficient search through the online marketplace, where you'll find many lenders with their Web pages, as they are ready to provide the best solutions in the competition. http://www.nocreditcheckloansx.co.uk/
ReplyDelete. The reimbursement span of the sum is for the brief time of time. The candidates have the capacity to pay back the acquired sum inside 7 days just. text loan
ReplyDeleteJob Oriented IT Online Training -H1B Visa, Work Permit and Job Placements
ReplyDelete5000 IT certified Consultants.Register at https://www.todaycourses.com
I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.
ReplyDeleteSAP training in Chennai
ReplyDeletenice blog too informative. looking and reading your points its so impressive. doing more blog like this. i really appreciated doing like this.
Digital Marketing For Small Business in Chennai
Best M Tech Colleges in Noida
ReplyDeleteBest M Tech Colleges in Delhi
Best M Tech Colleges in Gurgaon
Best M Tech Colleges in UP
Best M Tech Colleges in India
Best M Tech Colleges in Hyderabad
Best M Tech Colleges in Bangalore
Best M Tech Colleges in Chennai
I would really like to read some personal experiences like the way, you've explained through the above article. I'm glad for your achievements and would probably like to see much more in the near future. Thanks for share.
ReplyDeleteTablet unlocking service in chennai | tab service center in chennai | 100% genuine tablet parts | Tablet display replacement in chennai | Tablet Water damage service in chennai | 100% genuine tablet parts | Tablet Service center in chennai | Tablet unlocking service in chennai | Laptop display replacement service in chennai
Thanks for taking the time to discuss and share this with us, I for one feel strongly about it and really enjoyed learning more about this topic. Please share some more useful info on MBBS Consultants in Chandigarh also. I can see that you possess a degree of expertise on this subject.
ReplyDeleteThis is a great inspiring article. I am pretty much pleased with your good work. Please share good post on Carpet Washing in Thailand also Keep it up. Keep blogging. Looking to reading your next post.
ReplyDeleteoff white jordan 1
ReplyDeletekobe 9
yeezy boost
coach bags
coach factory outlet
golden goose outlet
curry 4 shoes
nike air max
bape hoodie
yeezy boost
I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
ReplyDeletejava advanced tutorials
j2ee training
very informative post shared by you. Thanks for sharing
ReplyDeleteDigital Marketing course in Delhi
Digital Marketing course in Noida