Showing posts with label aspiration2020. Show all posts
Showing posts with label aspiration2020. Show all posts

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

}
}

Read More

Infosys aspiration 2020 2013 college round question-3

// siddhu vydyabhushana // 115 comments
aspiration 2020 q&a

Pythagorean Math Test


Pythagoras is teaching mathematics to a class of N students. He wants to test if his students understood his new theorem.
He gives his students the length of the sides of a triangle and they have to tell him if it is a right triangle.

Input

First line an integer N, the number of students. 0<N<=50
Next N lines each containing 3 integers a, b and c which are the length of the sides of the triangle. 0<a,b,c.
(DO NOT PRINT ANY PROMPT MESSAGE TO READ THE INPUT.)

Output

If the given triangle is right angled print "RIGHT TRIANGLE" in a single line.
If the given triangle is not right angled print "NOT RIGHT TRIANGLE" in a single line.
(DO NOT PRINT ANY MESSAGE OTHER THAN THE SPECIFIED OUTPUT.)


Sample input

2
3 5 4
3 2 1

Sample output

RIGHT TRIANGLE
NOT RIGHT TRIANGLE


import java.util.Scanner;

class pymate
{
    public static void main(String args[])
 {
      int t,ki,i=0,j,c;
   Scanner s=new Scanner(System.in);
   t=s.nextInt();
   if(t>0 && t<=50)
   {
   int array[][]=new int[t][3];
   for (i = 0 ; i < t; i++ ) 
   {
      for(j=0;j<3;j++)
    {
                 array[i][j] = s.nextInt();
       }
         }
   for (i = 0 ; i < t; i++ ) 
   {
           
                 if((array[i][0] * array[i][0]) + (array[i][1]*array[i][1])==(array[i][2]*array[i][2]))
     {
        
          System.out.println("RIGHT TRIANGLE");
     }
     else
     if((array[i][0] * array[i][0]) == (array[i][1]*array[i][1])+(array[i][2]*array[i][2]))
     {
        
          System.out.println("RIGHT TRIANGLE");
     }
     else
     if((array[i][0] * array[i][0]) + (array[i][2]*array[i][2])==(array[i][1]*array[i][1]))
     {
        
          System.out.println("RIGHT TRIANGLE");
     }
     else
     {
         System.out.println("NOT RIGHT TRIANGLE");
     }
       
         }
   }
   
 }
}
Read More

Monday 7 October 2013

Infosys Aspiration 2020 2013 college round question-2

// siddhu vydyabhushana // 198 comments
Rahul has M friends and they love to play games with marbles. His little sister also wants to join his gang of marble game lovers.
To make it simple for his little sister Rahul creates a simple rule for the marble game of the day. Each participant will be given a set of marbles.
The participant is considered to win the game if they are able to pair up all the marbles they have; else they are said to lose.

Rahul being a coding freak writes a computer program to find out if his little sister would win the game or not. Help Rahul write the program.

infosys aspirations 2020


INPUT :
The line contains M, the number of friends rahul has. 1<=M<=50
It is followed by M lines, each containing the number of marbles each friend has.
0<M<=1000
(DO NOT PRINT ANY PROMPT ANY MESSAGE TO ENTER THE INPUT.)

OUTPUT:
For each of the M friends, first print the chronological index of the friend followed by a space, then state whether the participant won or lost.
(DO NOT PRINT ANY OTHER MESSAGE OTHER THAN THE RESULTS.)

SAMPLE INPUT :
5
1000
3
56
7
234
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class psmapa {
 public static void main (String args[]) throws IOException {  
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  int t = Integer.parseInt(in.readLine());
  int[] n=new int[t];
  int i=0;
  for(i=0;i<t;i++)
  {
  n[i]=Integer.parseInt(in.readLine());
  }
  for(i=0;i<t;i++)
  {  
     if(n[i]>0 && n[i]<=1000)
     {
     if(n[i]%2==0)
       {
        System.out.println(i+1+" won");
       }
    else
    {
        System.out.println(i+1+" lost");
    }
      }
   else
   {
         System.out.println(i+1+" invalid");
   }
  }
  
}
}

Read More

Infosys Aspiration 2020 2013 college round question-1

// siddhu vydyabhushana // 13 comments

Alice and Bob are being held at Azkaban(Prison). They want to escape and join Dumbledore's Army.
Alice wants to tell Bob about the details of the plan but wants to keep their escape plan from Dementors(the guards).
So Alice encrypts the message before passing the chits to Bob's cell.
However Bob was careless and he disposed the chits in his cell's waste paper bin.
The clever Dementor found the chits but couldn't make out what they said.
So he hired a computer programmer to decode the message for him. Please help the Dementor to decypher the message.
The code key that Alice used for this simple coding is a one for one character substitution based upon a single arithmetic manipulation of the printable portion of the ASCII character set.

infosys aspirations 2020

INPUT
The Encrypted message in a single line. The maximum number of charaters in a message is 100.
(DO NOT PRINT ANY PROMPT MESSAGE TO ENTER THE ENCRYPTED MESSAGE.)

OUTPUT
The decrypted message in a single line. (Do not print any other message other than the decrypted message.)

SAMPLE INPUT 1
[YHUZMVYT'[V'HUPTHN\Z'MVYT3

SAMPLE OUTPUT 1
TRANSFORM TO ANIMAGUS FORM,

SAMPLE INPUT 2
HUK'LZJHWL'^OLU'[OL`'IYPUN'MVVK5

SAMPLE OUTPUT 2
AND ESCAPE WHEN THEY BRING FOOD.




Answer:



import java.io.*;
class decyph{
public static void main(String args[])throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
char c;
     String kal;
       kal=in.readLine();
        for(int i=0;i<kal.length();i++){
           c=(char) (kal.charAt(i)-7);
           System.out.print(c);
        }
        System.out.println();
 }
}
Read More