Showing posts with label C-Prom 2016. Show all posts
Showing posts with label C-Prom 2016. Show all posts

Sunday, September 18, 2016

CPROM 2016 Q10 Adding Hexadecimal Number

Download Question Here

Change Snippet Background Color
 
import java.util.*;

/**
   Author : Hafiq
   Date :
**/

public class HexaDec{
   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[] split = scan.next().split(" ");
         
         int one = Integer.parseInt(split[0],16);
         int two = Integer.parseInt(split[1],16);
         
         System.out.println(Integer.toHexString(one+two).toUpperCase());
  
      }
      
   }
} 
 

CPROM 2016 Q9 SERIES OF NUMBERS

Download Question Here

Change Snippet Background Color
 
import java.util.*;


/**
   Author : Hafiq
   Date :
**/

public class NoPlate{

   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String in = scan.next();
      
      String[] split = in.split("(?<=\\D)(?=\\d)");
      
      int num = Integer.parseInt(split[1]);
      boolean tukar = false;
      String cur = split[0];
      
      for(int x=0;x<5;x++){
         num += 1;
         if(num > 9999){
            num = 1;
            tukar = true;
         }
         else
            tukar = false;
         
         int count = 0;   
         if(tukar){
            int z=0;
            while(true){
               if(cur.equals(plateStr(z))){
                  count = z;
                  break;
               }
               z++;
            }
            
            cur = plateStr(count+1);
         }
         
         System.out.println(cur+""+num);        
      }
   }
   
   static String plateStr(int x) {
      return x < 0?"":plateStr((x / 26) - 1) + (char)(65 + x % 26);
   }
   
   
   //ZZ9997
   //ZZ9998
   //ZZ9999
   //AAA1
   //AAA2
} 
 

CPROM 2016 Q8 LEXICOGRAPHIC ORDERING

Download Question Here

Change Snippet Background Color
 
import java.util.*;


/**
   Author : Hafiq
   Date :
**/

public class Lexi{
   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[] list = new String[cases];
      for(int x=0;x<cases;x++){
         list[x] = scan.next();
      }
      
      Arrays.sort(list);
      
      for(String ls:list)
         System.out.println(ls);
  }
  
} 
 

CPROM 2016 Q7 Simple Average And Median

Download Question Here

Change Snippet Background Color
 
import java.util.*;


/**
   Author : Hafiq
   Date :
**/

public class Aveg{
   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++){
         int count = scan.nextInt();
         String[] split = scan.next().split(" ");
         int [] num = new int[count];
         for(int z=0;z<count;z++){
            num[z] = Integer.parseInt(split[z]);
         }
         Arrays.sort(num);
         
         int median = 0;double mean = 0;
         int mid = count/2;
         
         if(count%2 == 0)
            median = (num[mid-1]+num[mid]) / 2;
         else
            median = num[mid];
                     
         for(int y=0;y<count;y++){
            mean += num[y];
         }
         
         System.out.println("Average:"+mean/count+" Median:"+median);
         
      }
   }
} 
 

CPROM 2016 Q6 Title Case

Download Question Here

Change Snippet Background Color
 
import java.util.*;


/**
   Author : Hafiq
   Date :
**/

public class TitleCase{
   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[] split = scan.next().split(" ");
         
         String temp = "";
         for(int y=0;y<split.length;y++){
            temp += (""+split[y].charAt(0)).toUpperCase() + split[y].substring(1,split[y].length());
            if(y<=split.length-1){
               temp+=" ";
            }
         }
         
         System.out.println(temp);
      }
   
   }
} 
 

CPROM 2016 Q5 Encryption

Download Question Here

Change Snippet Background Color
 
import java.util.*;


/**
   Author : Hafiq
   Date :
**/

public class Encryption{

   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      String input = scan.nextLine();
      
      String temp = "";
      int count = 1;
      for(int x=0;x<input.length();x++){
         char a = input.charAt(x);
         
         if(a == ' '){
            temp += (char)(a+count);
            count++;
         }
         else{
            temp += (char)(a+2);
         }
      }
      
      System.out.println(temp);
   
   }
} 
 

CPROM 2016 Q4 Pair Isograms

Download Question Here

Change Snippet Background Color

import java.util.*;

/**
   Author : Hafiq
   Date :
**/

public class PairIsoGram{
   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 input = scan.next();
         Map<Character, Integer> count = new HashMap<Character, Integer>();
         for(int y=0;y<input.length();y++){
            char c = input.charAt(y);
            if (count.containsKey(c)) {
                int cnt = count.get(c);
                count.put(c, ++cnt);
            } else {
                count.put(c, 1);
            }
         }        
         boolean flag = true;
         for(Map.Entry<Character, Integer> entry : count.entrySet()){
            if(entry.getValue() != 2){
               flag = false;
               break;
            }
         }         
         System.out.println(input+" --- "+ ((flag)?"pair program":"not pair isogram"));
      }       
   }
}

Saturday, September 17, 2016

CPROM 2016 Q3 Find The Winner

Download Question Here

Change Snippet Background Color
 
import java.util.*;


/**
   Author : Hafiq
   Date :
**/

public class Winner{
   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();
      
      int max = 0;
      String current = "";
      Event ev = new Event();
      List event = new ArrayList<>();
      for(int x=0;x(){
         @Override
         public int compare(Event e1,Event e2){
            if (e1.gold > e2.gold) {
               return -1;
            } else if (e1.gold < e2.gold) {
               return 1;
            } else {
               return 0;
            }
         }
      });
      
       
      for(Event e:event){
         System.out.println(e.toString());
      }
   }
}

class Event{
      public String name;
      public int gold;
      public int silver;
      public int bronze;
      
      public Event(){}
      
      public Event(String a,int b,int c, int d){
          name = a;
          gold = b;
          silver = c;
          bronze = d;
      }
      
      public String toString(){
         return name+" "+gold+" "+silver+" "+bronze;
      }
   }
 

CPROM2016 Q2 Split And Count

Download Question Here

Change Snippet Background Color
	
import java.util.*;
/**
   Author : Hafiq
   Date :
**/
public class splitString{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      String[] input = scan.nextLine().split("[\\s@&.;$?+-]+");
      System.out.println("Substrings length:"+input.length);
      for(int x=0;x<input.length;x++){
         System.out.println("Str["+x+"]"+input[x]+" Length:"+input[x].length());
      }
   }
}
	

CPROM2016 Q1 Multiplication Table

Download Question Here

Change Snippet Background Color
 
import java.util.*;
/**
   Author : Hafiq
   Date :
**/
public class multiplicationTable{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      int input = scan.nextInt();
      for(int x=1;x<=12;x++){
         System.out.println(x+"*"+input+"="+(x*input));
      }
   }
}