using System;
public class Test
{
public static void Main()
{
Console.WriteLine(FractionToDouble("4 1/5"));
}
private static double FractionToDouble(string fraction) {
double result;
if(double.TryParse(fraction, out result)) {
return result;
}
string[] split = fraction.Split(new char[] { ' ', '/' });
if(split.Length == 2 || split.Length == 3) {
int a, b;
if(int.TryParse(split[0], out a) && int.TryParse(split[1], out b)) {
if(split.Length == 2) {
return (double)a / b;
}
int c;
if(int.TryParse(split[2], out c)) {
return a + (double)b / c;
}
}
}
throw new FormatException("Not a valid fraction.");
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoJCUNvbnNvbGUuV3JpdGVMaW5lKEZyYWN0aW9uVG9Eb3VibGUoIjQgMS81IikpOwoJfQogICAgCiAgICBwcml2YXRlIHN0YXRpYyBkb3VibGUgRnJhY3Rpb25Ub0RvdWJsZShzdHJpbmcgZnJhY3Rpb24pIHsKICAgICAgICBkb3VibGUgcmVzdWx0OwogICAgCiAgICAgICAgaWYoZG91YmxlLlRyeVBhcnNlKGZyYWN0aW9uLCBvdXQgcmVzdWx0KSkgewogICAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgIH0KICAgIAogICAgICAgIHN0cmluZ1tdIHNwbGl0ID0gZnJhY3Rpb24uU3BsaXQobmV3IGNoYXJbXSB7ICcgJywgJy8nIH0pOwogICAgCiAgICAgICAgaWYoc3BsaXQuTGVuZ3RoID09IDIgfHwgc3BsaXQuTGVuZ3RoID09IDMpIHsKICAgICAgICAgICAgaW50IGEsIGI7CiAgICAKICAgICAgICAgICAgaWYoaW50LlRyeVBhcnNlKHNwbGl0WzBdLCBvdXQgYSkgJiYgaW50LlRyeVBhcnNlKHNwbGl0WzFdLCBvdXQgYikpIHsKICAgICAgICAgICAgICAgIGlmKHNwbGl0Lkxlbmd0aCA9PSAyKSB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIChkb3VibGUpYSAvIGI7CiAgICAgICAgICAgICAgICB9CiAgICAKICAgICAgICAgICAgICAgIGludCBjOwogICAgCiAgICAgICAgICAgICAgICBpZihpbnQuVHJ5UGFyc2Uoc3BsaXRbMl0sIG91dCBjKSkgewogICAgICAgICAgICAgICAgICAgIHJldHVybiBhICsgKGRvdWJsZSliIC8gYzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIAogICAgICAgIHRocm93IG5ldyBGb3JtYXRFeGNlcHRpb24oIk5vdCBhIHZhbGlkIGZyYWN0aW9uLiIpOwogICAgfQp9