/************************************************ Grundlegende Algorithmen mit Java, http://algorithmen-und-problemloesungen.de/ Copyright @2007-2008 by Doina Logofatu in C#: Michael Gärtner ************************************************/ using System; using System.IO; namespace Logofatu { class P7Equation { private static String FileInputName = "equation.in"; private static String FileOutputName = "equation.out"; private static IFormatProvider formatProvider = System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat; private static double sum(int n, double s, double p) { if ( 0 == n ) return 2; if ( 1 == n ) return s; return s * sum(n - 1, s, p) - p * sum(n - 2, s, p); } static void Main(string[] args) { StreamReader sr = null; StreamWriter sw = null; try { sr = new StreamReader(FileInputName); sw = new StreamWriter(FileOutputName); while ( !sr.EndOfStream ) { string[] sArray = sr.ReadLine().Split(' '); int n = int.Parse(sArray[0],formatProvider); double s = double.Parse(sArray[1],formatProvider); double p = double.Parse(sArray[2],formatProvider); sw.WriteLine(sum(n, s, p).ToString("g6", formatProvider)); } } catch ( IOException ex ) { Console.WriteLine("Fehler bei der Dateiverarbeitung!\n" + ex); } finally { if ( sr != null ) { sr.Close(); } if ( sw != null ) { sw.Close(); } } } } }