Informatika gyűjtemény

Egy szinttel feljebb mt_spam.cs

2004050607080910

NézetNyomtat

mt_spam.cs (Vissza)
Az alábbi letöltési lehetőségek közül választhatsz: (segítség)
Karakterkódolás:
Sortörés:
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 1 KB
/*
 * Készítette a SharpDevelop.
 * Felhasználó: 02cmezei
 * Dátum: 2008.02.18.
 * Ido: 15:55
 * 
 * A sablon megváltoztatásához használja az Eszközök | Beállítások | Kódolás | Szabvány Fejlécek Szerkesztését.
 */
using System;
using System.IO;
using System.Collections.Generic;

namespace Spam
{
    class Program
    {
        const int ABC=26;
        
        static string ch;
        static string[] fi;
        
        static string[] be;

        static int[] dp;
        static string s;
        
        public static int Munka()
        {
            string z=s;
            int[] r=dp;
            
            dp=new int[s.Length];
            for (int i=0; i!=dp.Length; i++) dp[i]=-1;
            Keres(0);
            return dp[0];
        }
        
        public static int Keres(int c)
        {
            int[] r=dp;
            if (c==s.Length) return 1;
            if (c>s.Length-1) return 0;
            if (dp[c]!=-1) return dp[c];
            dp[c]=0;
            for (int i=0; i!=ABC; i++)
            {
                int e=s.Length;
                int f=fi[i].Length;
                if (f+c-1<e)
                {
                    string ss=s.Substring(c,fi[i].Length);
                    if (ss==fi[i]) dp[c]+=Keres(c+fi[i].Length);
                }
            }
            
            return dp[c];
        }
        
        public static void Main(string[] args)
        {
            ReadCoding("spam.txt");
            Beolvas("spam.in");
            TextWriter tw=new StreamWriter("spam2.out");
            for (int i=0; i!=be.Length; i++)
            {
                s=Encode(be[i]);
                tw.WriteLine(Munka());
            }
            tw.Close();
        }
        
        public static string Encode(string e)
        {
            string o="";
            for (int i=0; i!=e.Length; i++)
            {
                o+=fi[ch.IndexOf(e[i])];
            }
            return o;
        }
        
        public static void Beolvas(string inp)
        {
            List<string> ls=new List<string>();
            TextReader tr=new StreamReader(inp);
            string l;
            while((l=tr.ReadLine())!="end") ls.Add(l);
            tr.Close();
            be=ls.ToArray();
        }
        
        public static void ReadCoding(string inp)
        {
            TextReader tr=new StreamReader(inp);
            ch="";
            fi=new string[ABC];
            for(int i=0; i!=ABC; i++)
            {
                string[] l=tr.ReadLine().Split(' ');
                ch+=l[0];
                fi[i]=l[1];
            }
            tr.Close();
        }
    }
}
(Vissza)