C# :: Aufgabe #137 :: Lösung #2

6 Lösungen Lösungen öffentlich
#137

Pig Latin - Schweine Latein

Anfänger - C# von DrizZle - 15.06.2016 um 13:57 Uhr
Hier zum Wikipedia Post

Einführung:

Zitat:

Pig Latin (engl.; wörtlich: Schweine-Latein) bezeichnet eine Spielsprache, die im englischen Sprachraum verwendet wird.
Sie wird vor allem von Kindern benutzt, aus Spaß am Spiel mit der Sprache oder als einfache Geheimsprache, mit der Informationen vor Erwachsenen oder anderen Kindern verborgen werden sollen.


Erklärung:

Zitat:

Beginnt das Wort mit einem Konsonanten, so wird der initiale Konsonant oder Konsonantencluster ans Ende des Wortes verschoben und ein „ay“ angehängt. Zu betrachten ist hierbei nicht die Rechtschreibung, sondern die tatsächliche Aussprache: „Stumme“ Konsonantenbuchstaben, wie z. B. das „h“ in „honor“, sind keine Konsonanten.

loser → oser-lay
button → utton-bay
star → ar-stay
three → ee-thray
question → estion-quay
happy → appy-hay
Pig Latin → Ig-pay Atin-lay

Beginnt das Wort mit einem Vokal oder einem stummen Konsonanten, so wird direkt ein „ay“ angehängt.

eagle → eagle-ay
America → America-ay
honor → honor-ay


Aufgabe:
Schreibt ein Programm welches ein belibiges Wort ins Schweine Latein umwandelt und ausgibt. Auf die Regel mit Stummen H's kann man verzichten.
#2
vote_ok
von Banger (50 Punkte) - 26.07.2016 um 08:57 Uhr
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;


namespace PigLatin
{
    class Program
    {
        static List<string> StringList = new List<string>();                // Vokallist
        
        static void Main(string[] args)
        {
            StringList.Add("a");                                             // filling it          
            StringList.Add("e");
            StringList.Add("i");
            StringList.Add("o");
            StringList.Add("u");
                                                                                      // variables
            string SWord = null;                                            // starting string
            string EWord = null;                                            // substring
            string End = null;                                               // endsting

            int StringLength = 0;                                           // sting length
            int SubLength = 0;                                              // substing length
            int Index = -1;                                                    // substing Index

            Console.Write("Type your Word: ");
            SWord = Console.ReadLine();                                     // gets string
            
            foreach (string search in StringList)                           // gets the Index for the first Vokal in the string
            {
                Index = SWord.IndexOf(search);
                if (Index >= 0)
                    break;
            }

            End = SWord.Substring(0, Index).ToString() + "ay";              // uses the index to split string and rearrange

            StringLength = SWord.Length;
            SubLength = StringLength - Index;
            

            EWord = SWord.Substring(Index, SubLength );                     // builds the final sting

            Console.Write("Translation: ");                                 // console output
            Console.WriteLine(EWord + End);
            Console.ReadKey();
        }
    }
}

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben