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.*;importjava.math.*;publicclassSolution{enumDataType{BYTE("byte",BigInteger.valueOf(Byte.MIN_VALUE),BigInteger.valueOf(Byte.MAX_VALUE)),SHORT("short",BigInteger.valueOf(Short.MIN_VALUE),BigInteger.valueOf(Short.MAX_VALUE)),INTEGER("int",BigInteger.valueOf(Integer.MIN_VALUE),BigInteger.valueOf(Integer.MAX_VALUE)),LONG("long",BigInteger.valueOf(Long.MIN_VALUE),BigInteger.valueOf(Long.MAX_VALUE));privateStringname;privateBigIntegerlowValue;privateBigIntegerupValue;DataType(Stringname,BigIntegerlowValue,BigIntegerupValue){this.name=name;this.lowValue=lowValue;this.upValue=upValue;}publicStringgetName(){returnname;}publicbooleanfitted(BigIntegernumber){returnlowValue.compareTo(number)<=0&number.compareTo(upValue)<=0;}publicstaticEnumSet<DataType>findAllFitted(BigIntegernumber){EnumSet<DataType>results=EnumSet.noneOf(DataType.class);for(DataTypedataType:values()){if(dataType.fitted(number)){results.add(dataType);}}returnresults;}}publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannersc=newScanner(System.in);intn=sc.nextInt();BigInteger[]nums=newBigInteger[n];for(inti=0;i<n;i++){nums[i]=sc.nextBigInteger();}for(BigIntegernum:nums){EnumSet<DataType>dataTypes=DataType.findAllFitted(num);if(dataTypes.isEmpty()){System.out.println(num+" can't be fitted anywhere.");}else{System.out.println(num+" can be fitted in:");for(DataTypedataType:dataTypes){System.out.println("* "+dataType.getName());}}}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Datatypes
You are viewing a single comment's thread. Return to all comments →