/************************************************ 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 P6BaseP { private static String FileInputName = "baseP.in"; private static String FileOutputName = "baseP.out"; private static void transfBase10ToP(long n, int p, StreamWriter sw) { if ( n > 0 ) { transfBase10ToP(n / p, p, sw); sw.Write(n % 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(' '); long n = long.Parse(sArray[0]); int p = int.Parse(sArray[1]); sw.Write("{0,10:d} zur Basis {1:d} = ", n, p); transfBase10ToP(n, p, sw); sw.WriteLine(); } } catch ( IOException ex ) { Console.WriteLine("Fehler bei der Dateiverarbeitung!\n" + ex); } finally { if ( sr != null ) { sr.Close(); } if ( sw != null ) { sw.Close(); } } } } }