Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
2.8 kB
2
Indexable
Never
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.CodeDom;

namespace Lab4
{
    internal class Program
    {
        const string CFd = "..\\..\\U1.txt";
        const string CFr = "..\\..\\Rezultatai.txt";
        static void Main(string[] args)
        {
            char[] skyrikliai = { ' ', '.', ',', '!', '?', ':', ';', '(', ')', '-', '~', '\t' };
            Apdoroti(CFd, CFr, skyrikliai);
            PradiniaiDuomenys(CFd);
        }
        static void PradiniaiDuomenys(string fv)
        {
            string[] lines = File.ReadAllLines(fv, Encoding.UTF8);
            {
                foreach (string line in lines)
                {
                    if (line.Length > 0)
                    {
                        Console.WriteLine(line);
                    }
                }
            }
        }
        static void Apdoroti(string fv, string fvr, char[] skyrikliai)
        {
            string[] lines = File.ReadAllLines(fv, Encoding.UTF8);
            using (var fr = File.CreateText(fvr))
            {
                string naujas = "";
                foreach (string line in lines)
                {
                    if (line.Length > 0)
                    {
                        naujas = SkirtingiSimboliai(line, skyrikliai);
                    }
                    fr.WriteLine(naujas);
                }
            }
        }
        static string SkirtingiSimboliai(string line, char[] skyrikliai)
        {
            string naujas = line;
            string[] parts = line.Split(skyrikliai, StringSplitOptions.RemoveEmptyEntries);
            int dydis = 0;
            for (int i = 0; i < parts.Length; i++)
            {
                char[] zparts = parts[i].ToCharArray();
                for (int j = 0; j < zparts.Length; j++)
                {
                    for (int k = 0; k < zparts.Length; k++)
                    {
                        if (zparts[j] == zparts[k] && j != k)
                        {
                            dydis = 0;
                            j = zparts.Length;
                            break;
                        }
                        else if (j != k && zparts[j] != zparts[k])
                        {
                            dydis = 1;
                            continue;
                        }
                    }
                }
                if (dydis == 1)
                {
                    naujas = naujas.Replace(parts[i], "");
                    naujas = naujas.Replace("  ", " ");                    
                }
            }
            return naujas;
        }
    }
}
Leave a Comment