We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */List<Integer>ascii=newArrayList<>();Scannersc=newScanner(System.in);intn=sc.nextInt();for(inti=0;i<n;i++)ascii.add(sc.nextInt());sc.close();Map<Integer,Integer>freq=newHashMap<>();StringBuilderkey=newStringBuilder();for(inti=0,time=0;;i+=3){if(i>=ascii.size()){intwhich=0,count=0;for(Map.Entry<Integer,Integer>entry:freq.entrySet()){if(entry.getValue()>count){which=entry.getKey();count=entry.getValue();}}key.append((char)(' '^which));if(time==0)i=1;elseif(time==1)i=2;elsebreak;time++;freq.clear();}intt=ascii.get(i);if(!freq.containsKey(t))freq.put(t,1);elsefreq.put(t,freq.get(t)+1);}System.out.print(key);}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #59: XOR decryption
You are viewing a single comment's thread. Return to all comments →
JAva code