import eprog.*; import java.math.*; public class Farbcode { static String[] farben = {"sw", "br", "rt", "or", "ge", "gn", "bl", "vi", "gr", "ws"}; static String[] exponenten = {"si", "go", "sw", "br", "rt", "or", "ge", "gn", "bl", "vi", "gr", "ws"}; public static void main(String[] args) { boolean error = false; double resistance; int exponent = 0; double epsilon = 0.001; resistance = readResistance(); error = resistance < 0.; if (! error) { exponent = (int) (Math.log(resistance+epsilon)/Math.log(10.)) - 2; error = (resistance < 1.) || (exponent > 9); } if (! error) { resistance /= Math.pow(10.,exponent); if (Math.ceil(resistance) == Math.floor(resistance)) EprogIO.println(colorCode(resistance,exponent)); else { EprogIO.print(colorCode(Math.ceil(resistance),exponent)); EprogIO.print(" "); EprogIO.println(colorCode(Math.floor(resistance),exponent)); } } else EprogIO.println("FALSCHE EINGABE"); } public static double readResistance() { double resistance; String input; double exponent = 1.; input = EprogIO.readWord(); if (input.indexOf('K') > 0) { exponent = 1000.; input = input.replace('K','.'); } else if (input.indexOf('M') > 0) { exponent = 1000000.; input = input.replace('M','.'); } else if (input.indexOf('R') > 0) input = input.replace('R','.'); try { resistance = Double.valueOf(input).doubleValue()*exponent; } catch (NumberFormatException e) { resistance = 0.; } return(resistance); } public static String colorCode(double resistance, int exponent) { String code = "["; int digit; for (int i=100; i >= 1; i/=10) { digit = ((int) (resistance/i)) % 10; code += farben[digit]; code += " "; } code += exponenten[exponent+2]; code += "]"; return(code); } }