Thursday 10 October 2013

Infosys aspration 2020 2013 college round question-4

// siddhu vydyabhushana // 12 comments
aspiration-2020 translator

  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]);

}
}

12 comments:

  1. 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
  2. . 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

    ReplyDelete
  3. Job Oriented IT Online Training -H1B Visa, Work Permit and Job Placements
    5000 IT certified Consultants.Register at https://www.todaycourses.com

    ReplyDelete
  4. 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.

    SAP training in Chennai

    ReplyDelete

  5. nice 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

    ReplyDelete
  6. 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.
    Tablet 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

    ReplyDelete
  7. 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.

    ReplyDelete
  8. This 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.

    ReplyDelete
  9. 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.

    java advanced tutorials
    j2ee training

    ReplyDelete