import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); while(scanner.hasNext()) { String s = scanner.next(); String c=s.replaceAll("[a-zA-Z]",""); double x=Double.parseDouble(c); double temp; if(x==0) { break; } if(s.charAt(s.length()-2)=='K') { temp = x*(1024-1000); System.out.println(String.format("%.0f", temp)); }else if(s.charAt(s.length()-2)=='M') { temp = x*Math.pow(1024, 2) - x*Math.pow(1000, 2); System.out.println(String.format("%.0f", temp)); }else if(s.charAt(s.length()-2)=='G') { temp = x*Math.pow(1024, 3) - x*Math.pow(1000, 3); System.out.println(String.format("%.0f", temp)); }else if(s.charAt(s.length()-2)=='T') { temp = x*Math.pow(1024, 4) - x*Math.pow(1000, 4); System.out.println(String.format("%.0f", temp)); }else { System.out.println(0); } } scanner.close(); } } |
Double click to view unformatted code.