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.nextLine(); StringBuilder num=new StringBuilder(); for(char c:s.toCharArray()){ if(c>='0'&&c<='9'){ num.append(c); } else{ break; } } double i= Double.parseDouble(num.toString()); if(i==0){ break; } double ans=0; switch (s.substring(num.length())){ case "B": ans=0; break; case "KB": ans= (i*(Math.pow(1024,1)-Math.pow(1000,1))); break; case "MB": ans= (i*(Math.pow(1024,2)-Math.pow(1000,2))); break; case "GB": ans= (i*(Math.pow(1024,3)-Math.pow(1000,3))); break; case "TB": ans= (i*(Math.pow(1024,4)-Math.pow(1000,4))); break; } System.out.printf("%.0f\n",ans); } } } |
Double click to view unformatted code.