Showing posts with label Mock. Show all posts
Showing posts with label Mock. Show all posts

Thursday, September 17, 2015

The Block Game (Mock KICTM UiTM Jasin 2015)

The citizens of Byteland regularly play a game. They have blocks each denoting some integer from 0 to 9. These are arranged together in a random manner without seeing to form different numbers keeping in mind that the first block is never a 0. Once they form a number they read in the reverse order to check if the number and its reverse is the same. If both are same then the player wins. We call such numbers palindrome

Ash happens to see this game and wants to simulate the same in the computer. As the first step he wants to take an input from the user and check if the number is palindrome and declare if the user wins or not

Input

The first line of the input contains T, the number of test cases. This is followed by T lines containing an integer N.

Output

For each input output "wins" if the number is a palindrome and "losses" if not.
Constraints

1<=T<=20
1<=N<=10000

Input:
3
331
666
343

Output:
losses
wins
wins


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.*;
import java.lang.*;
import java.math.*;

public class Mock4{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
      
      int cases = scan.nextInt();
      
      for(int x=0;x<cases;x++){
         
         String get = scan.next();

         StringBuilder str = new StringBuilder(get);
         
         if(get.equals(str.reverse().toString()))
            System.out.println("wins");
         else
            System.out.println("loses"); 
         
      }
   }
}

Find Remainder (Mock KICTM UiTM Jasin 2015)

Write a program to find the remainder when two given numbers are divided.

Input and Output

The first line contains an integer T, total number of test cases. Then follow T lines, each line contains two integers A and B. Find remainder when A is divided by B

Constraints
1 <= T <= 1000
1 <=A,B <== 10000


Samples Input
3
1 2
100 200
10 40

Samples Output
1
100
10



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.*;
import java.lang.*;
import java.math.*;

public class Mock4{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
      
      int cases = scan.nextInt();
      
      for(int x=0;x<cases;x++){
         
         String [] get = scan.next().split(" ");

         System.out.println(Integer.parseInt(get[0]) % Integer.parseInt(get[1]));
         
      }
   }
}

Typo! (Mock KICTM UiTM Jasin 2015)

A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner.



Input

Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control, etc.] are not represented in the input.

Output

You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the output.

Sample Input

O S, GOMR YPFSU/

Sample Output

I AM FINE TODAY.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.*;
import java.lang.*;
import java.math.*;

public class Mock3{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
      
      String get = scan.next();
      
      String str = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
      
      String ans="";
      for(int x=0;x<get.length();x++){
         if(get.charAt(x) != ' '){
            for(int y=0;y<str.length();y++){
               if(get.charAt(x) == str.charAt(y)){
                  ans = ans +""+ str.charAt(y-1);
                  break;
               }
            }
         }
         else{
            ans = ans + " ";
         }
      }
      
      System.out.print(ans);
    
   }
}

No Brainer (Mock KICTM UiTM Jasin 2015)

Zombies love to eat brains. Yum.

Input

The first line contains a single integer n indicating the number of data sets.

The following n lines each represent a data set. Each data set will be formatted according to the following description:

A single data set consists of a line "X Y", where X is the number of brains the zombie eats and Y is the number of brains the zombie requires to stay alive.

Output

For each data set, there will be exactly one line of output. This line will be "MMM BRAINS" if the number of brains the zombie eats is greater than or equal to the number of brains the zombie requires to stay alive. Otherwise, the line will be "NO BRAINS".

Sample Input

3
4 5
3 3
4 3

Sample Output

NO BRAINS
MMM BRAINS
MMM BRAINS



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.*;
import java.lang.*;
import java.math.*;

public class Mock2{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
      
      int cases = scan.nextInt();
      
      for(int x=0;x<cases;x++){
         
         String [] get = scan.next().split(" ");
         
         if(Integer.parseInt(get[0]) < Integer.parseInt(get[1]))
            System.out.println("NO BRAINS");
         else
            System.out.println("MMM BRAINS");
         
      }
   }
}

Sum It Up (Mock KICTM UiTM Jasin 2015)

The input begins with an integer K (0<=K<=100) which denotes the numbers of the test cases. This line is followed by K lines with a list of integers. The first value, N (1<=N <= 50), indicates the numbers of integers for the list, followed by N integers with value more than 0 ans less then 999999.

Sample input
2
4 3 2 1 1
3 4 5 5

Samples Output
7
14


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.*;
import java.lang.*;
import java.math.*;

public class Mock1{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
      
      int cases = scan.nextInt();
      
      for(int x=0;x<cases;x++){
         
         String [] get = scan.next().split(" ");
         
         int total=0;
         for(int y=1;y<get.length;y++){
            total = total + Integer.parseInt(get[y]);
         }
         
         System.out.println(total);
         
      }
   }
}