Pages

Sunday, August 14, 2016

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;
    }
}


No comments:

Post a Comment