Sunday, August 14, 2016

PROMED@CS 2012 Question 6 (Even Or Odd Wins!)

Download Question Here

Change Snippet Background Color
          
            
          

import java.util.*;
import java.io.*;
import java.math.*;

/**
 * Created by Hafiq Iqmal on 14/8/2016.
 * PROMED CS 2012
 */

public class EvenOrOdd{
   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();
      String [] ans = new String[cases];
      
      for(int x=0;x<cases;x++){
         int num = scan.nextInt();
         
         int cube = num * num * num;
         boolean even = false;
         boolean odd = false;
         
         while(cube > 0){
            if(((cube % 10) % 2 == 0)){
               even = true;
            }
            else{
               odd = true;
            }
            
            cube /= 10;            
         }
         
                  
         if(even && !odd){
            ans[x] = "Case #"+(x+1)+": EVEN";
         }
         else if(!even && odd){
            ans[x] = "Case #"+(x+1)+": ODD";
         }
         else{
            ans[x] = "Case #"+(x+1)+": MIXED";
         }
      }
      
      for(int x=0;x<cases;x++){
         System.out.println(ans[x]);
      }
   }
}

        

PROMED@CS 2012 Question 5 (Dash Pattern)

Download Question Here

Change Snippet Background Color
          
import java.util.*;
import java.io.*;

/**
 * Created by Hafiq Iqmal on 14/8/2016.
 * PROMED CS 2012
 */

public class DashPattern{

   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();
      String [] ans = new String[cases];
      
      for(int x=0;x<cases;x++){
         String[] split = scan.next().split("\\s+");
         
         String tiang = "|";
         String draw = "";
         
         int[] num = new int[split.length];
         
         for(int z=0;z<split.length;z++){
            num[z] = Integer.parseInt(split[z]);
         }
         
         int len = num[0];
         
         int current = 0;
         boolean selang = true;
         
         while(current < len){
            for(int y=1;y<num.length;y++){
                  for(int index=0;index<num[y];index++){
                     if (current < len){
                        if(y%2 == 1)
                           draw += "_";
                        else
                           draw += " ";
                     }
                     else{
                        break;
                     }
                     current ++;
                  }
                                
               selang = (selang)?false:true;
            }
         }
         
         ans[x] = "Case #"+(x+1)+": "+tiang+draw+tiang;
      }
      
      for(int x=0;x<cases;x++){
         System.out.println(ans[x]);
      }
      
   }

}
          
        

PROMED@CS 2012 Question 4 (Hail Taxi)

Download Question Here

Change Snippet Background Color

import java.util.*;
import java.io.*;

/**
 * Created by Hafiq Iqmal on 14/8/2016.
 * PROMED CS 2012
 * Using bruteforce closest pairing coordinate
 */

public class HailTaxi {
    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();
        String[] ans = new String[cases];

        for (int x = 0; x < cases; x++) {
            List <Coordinate> list = new ArrayList <>();
            String[] p = scan.next().trim().split(" ");
            
            Coordinate player = new Coordinate(Double.parseDouble(p[0]), Double.parseDouble( p[1]));
            
            while (true) {
                String input = scan.next().trim();
                if (input.equals("10001 10001"))
                    break;
                else {
                    String[] in = input.split(" ");
                    list.add(new Coordinate(Double.parseDouble(in[0]), Double.parseDouble(in[1])));
                }
            }
            
            list.add(new Coordinate(0,0));
            Collections.sort(list);
                        
            Coordinate bf = findNearest(list,player);

            ans[x] = "Case #" + (x + 1) + ": " + bf;
        }

        for (int x = 0; x < cases; x++) {
            System.out.println(ans[x]);
        }
    }

    private static class Coordinate implements Comparable<Coordinate> {
        private double x;
        private double y;

        public Coordinate(double x, double y) {
            this.x = x;
            this.y = y;
        }

        public double getX() {
            return x;
        }

        public double getY() {
            return y;
        }
        
        @Override
        public int compareTo(Coordinate p){
            if(y - p.y != 0){
                return (int)(y - p.y);
            }
 
            if(x - p.x != 0){
                return (int)(x - p.x);
            }
 
            return 0;
        }

        public String toString() {
            return (int)x + " " + (int)y;
        }
    }

 
    private static double calDistance(Coordinate a,Coordinate p){
        return (a.getX()-p.getX())*(a.getX()-p.getX()) + (a.getY()-p.getY())*(a.getY()-p.getY());
    }

    private static Coordinate findNearest(List <Coordinate> points, Coordinate player) {        
        Coordinate closest = points.get(0);
        for (Coordinate coor:points) {            
            if (calDistance(coor,player) <= calDistance(closest, player))
               closest = coor;
        }
        
        return closest;
    }
   
}

PROMED@CS 2012 Question 3 (Count Sub Sequence)

Download Question Here

Change Snippet Background Color
          
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Hafiq Iqmal on 14/8/2016.
 * PROMED CS 2012
 */
public class CountSubSequence{

    static final int MODULES = 1000000003;

    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();
        String[] ans = new String[cases];

        for (int x = 0; x < cases; x++) {

            String first = scan.next();
            String second = scan.next();

            List<String> fList = getForwardPermutation(first);
            List<String> sList = getForwardPermutation(second);

            ans [x] ="Case #"+(x+1)+": "+countSS(fList,sList);
        }

        for (int x = 0; x < cases; x++) {
            System.out.println(ans[x]);
        }
    }

    private static int countSS(List<String> flist,List<String> slist){
        // swap which is greater
        if (flist.size() < slist.size()){
            List<String> temp  = flist;
            flist = slist;
            slist = temp;
        }

        int count = 0;

        for (String aFlist : flist) {
            for (String aSlist : slist) {
                if (aFlist.equals(aSlist)) {
                    count++;
                }
            }
        }

        return count % MODULES;
    }

    private static List<String> getForwardPermutation(String text) {
        List<String> res = new ArrayList<>();
        for (int i = 0; i < text.length(); i++) {
            int lenRes = res.size();
            for (int j = 0; j < lenRes; j++) {
                res.add(text.charAt(i) + res.get(j));
            }
            res.add(Character.toString(text.charAt(i)));
        }
        // put null at first list
        res.add(0,"");

        return res;
    }

}
     
          
        

PROMED@CS 2012 Question 2 (Matrix Reloaded)

Download Question Here

Change Snippet Background Color

import java.util.*;

/**
 * Created by Hafiq Iqmal on 14/8/2016.
 * PROMED CS 2012
 */


public class MatrixReloaded{
    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();
        String [] ans = new String[cases];

        for(int x=0;x<cases;x++){
            String binary = scan.next();
            int len = binary.length();
            boolean range = (len > 100 && len < 65535);
            int count = 0;
            if(range){
                for(int y=0;y<len;y++){
                    if(binary.charAt(y) == '1'){
                        int z = y+1;
                        if (z>=len){
                            if(binary.charAt(y) == '1') {
                                count++;
                            }
                            break;
                        }
                        else {
                            while (true) {
                                if (z < len) {
                                    if (binary.charAt(z) == '0') {
                                        y = z;
                                        count++;
                                        break;
                                    }
                                } else {
                                    break;
                                }

                                z++;
                            }
                        }
                    }
                    else{
                        y++;
                    }
                }
                ans[x] = "Cases #"+(x+1)+": "+count;
            }
            else{
                ans[x] = "Cases #"+(x+1)+": -1";
            }
        }

        for (int x=0;x<cases;x++){
            System.out.println(ans[x]);
        }
    }
}

PROMED@CS 2012 Question 1 (P-LOCK)

Download Question Here

Change Snippet Background Color

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * Created by Hafiq Iqmal on 14/8/2016.
 * PROMED CS 2012
 */
public class PLock {

    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();
        String [] ans = new String[cases];

        for(int x=0;x2 && get.matches("[A-Z]+")){
                if (!findDuplicate(get))
                    ans[x] = "Case #"+(x+1)+": VALID";
                else
                    ans[x] = "Case #"+(x+1)+": INVALID";
            }
            else
                ans[x] = "Case #"+(x+1)+": INVALID";

        }

        for (int x=0;x map = new HashMap<>();
        char[] getChar = str.toCharArray();
        for(Character isDuplicate:getChar){
            if(map.containsKey(isDuplicate)){
               // plus 1 if found same character     
               map.put(isDuplicate, map.get(isDuplicate)+1);
            } else {
               // add 1 to new Character
               map.put(isDuplicate, 1);
            }
        }
        Set keys = map.keySet();
        for(Character isDuplicate:keys){
            if(map.get(isDuplicate) > 1){
                //found more than 1
                return true;
            }
        }

        return false;
    }
}


Best Application to learn Difference Programming Languages Fast


App Name: Programming Hub
Package Name: com.freeit.java
Category: Education
Developer : Nexino Labs Pvt Ltd
Version: 3.0.6
Publish Date: July 30, 2016
File Size: Undefined
Installs: 1,000,000 - 5,000,000
Requires Android: 4.1 and up
Content Rating: Everyone
Developer: Visit website Email contactus@prghub.com


This is the best Application for me to Learn 18+ Programming languages such as Python, Assembly, HTML, VB.NET, C, C++, C# (CSharp), JavaScript, PHP, Ruby, R Programming, CSS, Java programming and much more! The new UI is quite interesting with new Material Design include the built-in playground where you can test your code in one app :D

With this app, i think is fastest way to learn any programming language by referring ready made programs and theory created by programming experts. Just download the language you want to learn or just request to the developer on what language you want or solutions.

Have an exam tomorrow?? :D No worries! By this app, forget your 600 page textbooks! Simply read this app essential and very precise reference material to score awesome marks!

Below is the Screenshot of this lastest app