All pastes #2118134 Raw Edit

Anonymous

public text v1 · immutable
#2118134 ·published 2012-02-11 20:30 UTC
rendered paste body
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApplication1
{

    class Program1
    {
        static char[] sesli = { 'A', 'a', 'E', 'e', 'İ', 'i', 'I', 'ı', 'Ü', 'ü', 'U', 'u', 'Ö', 'ö', 'O', 'o' };
        static char[] sessiz = { 'B', 'b', 'C', 'c', 'Ç', 'ç', 'D', 'd', 'F', 'f', 'G', 'g', 'Ğ', 'ğ', 'H', 'h', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'P', 'p', 'R', 'r', 'S', 's', 'Ş', 'ş', 'T', 't', 'V', 'v', 'Y', 'y', 'Z', 'z' };
        static char[] sembol = {' ', ',', '"', '!', '^', '.', ':', ';', '?', '-', '_', '(', ')', '[', ']', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

        static void Main(string[] args)
        {
           while(true)
           {
               Console.WriteLine("Lütfen Hecelenecek Cümleyi Giriniz:");
               string cumle = Console.ReadLine();
               Console.Clear();
               var kelimeler = KelimelereAyir(cumle);

               foreach (var kelime in kelimeler)
	           {
                   var heceler = HecelereAyir(kelime);
                   Console.WriteLine(kelime + " :");
		            foreach (var hece in heceler)
	                {
		                Console.Write(hece + " ");
	                }
                   Console.WriteLine();
	           }
           }
        }

        static List<string> KelimelereAyir(string cumle)
        {
            return cumle.Split(sembol).ToList();
        }

        static List<string> HecelereAyir(string kelime)
        {
            List<string> heceler = new List<string>();

            string hece = "";
            for (int i = 0; i < kelime.Length; i++)
			{
                if(Icindemi(sessiz, kelime[i]))
                        if((i== kelime.Length-1)||((i< kelime.Length-1) && Icindemi(sessiz,kelime[i+1])))
                        {
                            hece += kelime[i];
                            if (i == kelime.Length - 2 || (i < kelime.Length - 2 && Icindemi(sessiz, kelime[i + 2])))
                            {
                                hece += kelime[i + 1];
                                i += 1;
                            }
                            heceler.Add(hece);
                            hece = "";
                        }
                        else
                        {
                            heceler.Add(hece);
                            hece = kelime[i].ToString(); ;
                        }
                if (Icindemi(sesli, kelime[i]))
                {
                    if (hece != "" && Icindemi(sesli, hece[hece.Length - 1]))
                    {
                        heceler.Add(hece);
                        hece = "";
                    }
                    hece += kelime[i];
                }

		}
            heceler.Add(hece);

            return heceler.Where(h => h.Length>0).ToList();
        }

        static bool Icindemi(char[] chars, char c)
        {
            foreach (var i in chars)
	            if(i==c) return true;
            return false;
        }
    }
}