Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.30 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace ConsoleApp2
  5. {
  6.     class Program
  7.     {
  8.         const string CFd = "duomenys.txt";
  9.         const string CFr = "rez.txt";
  10.         static void Main(string[] args)
  11.         {
  12.             string sep = " ,./`-:;()?!";
  13.             string zod;
  14.             string zod2;
  15.             int me = 0;
  16.             int me2 = 0;
  17.             RastiZTekste(CFd, sep, out zod, ref me);
  18.             Console.WriteLine("{0} {1}", zod , me+1);
  19.             // PerkeltiEilute(CFd, CFd, me);
  20.             RastiZTtekste(CFd, sep, out zod2, ref me2);
  21.             Console.WriteLine("{0} {1}", zod2, me2 + 1);
  22.             IstryntiTZodi(CFd, zod2, sep, CFr);
  23.         }
  24.         static int SkirtLygSk(string e)
  25.         {
  26.             int kiek = 0;
  27.             char[] lyginiai = { '2', '4', '6', '8' };
  28.             for(int i = 0; i < lyginiai.Length; i++)
  29.             {
  30.                 if(e.IndexOf(lyginiai[i]) >= 0)
  31.                 {
  32.                     kiek++;
  33.                 }
  34.             }
  35.             return kiek;
  36.         }
  37.         static int SkirtBalsiuSkaicius(string e)
  38.         {
  39.             int kiek = 0;
  40.             string b = "aAeEiIoOyYUu";
  41.             char[] balses = b.ToCharArray();
  42.             for (int i = 0; i < balses.Length; i++)
  43.             {
  44.                 if(e.IndexOf(balses[i]) >= 0)
  45.                 {
  46.                     kiek++;
  47.                 }
  48.             }
  49.             return kiek;
  50.  
  51.         }
  52.         //static void IstryntiTZodi(string fvd, string zod2, string sep, string fvr)
  53.         //{
  54.         //    using (StreamReader reader = new StreamReader(fvd))
  55.         //    {
  56.         //        string eilute;
  57.         //        using (var fr = File.CreateText(fvr))
  58.         //        {
  59.         //            while ((eilute = reader.ReadLine()) != null)
  60.         //            {
  61.         //                char[] sk = sep.ToCharArray();
  62.         //                string[] parts = eilute.Split(sk, StringSplitOptions.RemoveEmptyEntries);
  63.         //                int pr = 0;
  64.         //                string z;
  65.         //                foreach (string zod in parts)
  66.         //                {
  67.         //                    pr = zod.IndexOf(zod2);
  68.         //                    if (pr >= 0)
  69.         //                    {
  70.         //                        fr.Write("{0}", zod.Remove(pr));
  71.         //                    }
  72.         //                    else
  73.         //                    {
  74.         //                        fr.Write(" {0}", zod);
  75.         //                    }
  76.         //                }
  77.         //                fr.WriteLine();
  78.         //            }
  79.         //        }
  80.         //    }
  81.         //}
  82.         static void IstryntiTZodi(string fvd, string zod2, string sep, string fvr)
  83.         {
  84.             string eilute;
  85.             char[] sk = sep.ToCharArray();
  86.             using (StreamReader reader = new StreamReader(fvd))
  87.             {
  88.                 int pr = 0;
  89.                 while ((eilute = reader.ReadLine())!=null)
  90.                 {
  91.                     string[] parts = eilute.Split(sk, StringSplitOptions.RemoveEmptyEntries);
  92.                     foreach (string zod in parts)
  93.                     {
  94.                         pr = zod.IndexOf(zod2);
  95.                         if (pr>=0)
  96.                         {
  97.                             Console.Write("{0}", zod.Remove(pr));
  98.                         }
  99.                         else
  100.                         {
  101.                             Console.Write(" {0}", zod);
  102.                         }
  103.                     }
  104.                     Console.WriteLine();
  105.                 }
  106.             }
  107.  
  108.         }
  109.  
  110.  
  111.         //static void IstryntiTZodi(string fvd, string zod2, string sep)
  112.         //{
  113.         //    char[] s = sep.ToCharArray();
  114.         //    string[] lines = File.ReadAllLines(fvd);
  115.         //    int i = 0;
  116.         //    int pr = 0;
  117.         //    foreach(string line in lines)
  118.         //    {
  119.         //        string[] parts = line.Split(s, StringSplitOptions.RemoveEmptyEntries);
  120.         //        pr = parts.IndexOf(zod2);
  121.         //        Console.WriteLine(pr);
  122.         //        if(pr >=0)
  123.         //        {
  124.         //            Console.WriteLine("{0}", line.Remove(pr));
  125.         //        }
  126.         //        else
  127.         //        {
  128.         //            Console.WriteLine(line);
  129.         //        }
  130.         //        i++;
  131.         //    }
  132.         //}
  133.         static string RastiTZodiEil(string e, string sk)
  134.         {
  135.             char[] sep = sk.ToCharArray();
  136.             string[] parts = e.Split(sep, StringSplitOptions.RemoveEmptyEntries);
  137.             int trump = int.MaxValue;
  138.             string trumpiausias = "";
  139.             foreach(string zod in parts)
  140.             {
  141.                 if(zod.Length<trump && SkirtBalsiuSkaicius(zod) == 3)
  142.                 {
  143.                     trumpiausias = zod;
  144.                     trump = zod.Length;
  145.                 }
  146.             }
  147.             return trumpiausias;
  148.         }
  149.         static void RastiZTtekste(string fv, string sk, out string zod, ref int me)
  150.         {
  151.             string trump="";
  152.             string z = "";
  153.             int tr = int.MaxValue;
  154.             int i = 0;
  155.             using (StreamReader reader = new StreamReader(fv))
  156.             {
  157.                 string eilute;
  158.                 while ((eilute = reader.ReadLine()) != null)
  159.                 {
  160.                     trump = RastiTZodiEil(eilute, sk);
  161.                     if (trump.Length < tr)
  162.                     {
  163.                         tr = trump.Length;
  164.                         z = trump;
  165.                         me = i;
  166.                     }
  167.                     i++;
  168.                 }
  169.             }
  170.             zod = z;
  171.  
  172.         }
  173.         static string RastiZodiEil(string e, string sk)
  174.         {
  175.             char[] sep = sk.ToCharArray();
  176.             string[] parts = e.Split(sep, StringSplitOptions.RemoveEmptyEntries);
  177.             string ilgiausias = "";
  178.             foreach(string zod in parts)
  179.             {
  180.                 if(zod.Length > ilgiausias.Length && SkirtBalsiuSkaicius(zod) == 3)
  181.                 {
  182.                     ilgiausias = zod;
  183.                 }
  184.             }
  185.             return ilgiausias;
  186.         }
  187.         static void RastiZTekste(string fv, string sk, out string zod, ref int me)
  188.         {
  189.             string z;
  190.             string eilute;
  191.             string ilgiausias = "";
  192.             int i = 0;
  193.             using(StreamReader reader = new StreamReader(fv))
  194.             {
  195.                 while((eilute = reader.ReadLine()) != null)
  196.                 {
  197.  
  198.                     z = RastiZodiEil(eilute, sk);
  199.                     if(z.Length > ilgiausias.Length)
  200.                     {
  201.                         ilgiausias = z;
  202.                         me = i;
  203.                     }
  204.                     i++;
  205.                 }
  206.             }
  207.             zod = ilgiausias;
  208.         }
  209.         static void PerkeltiEilute(string fvd, string fvr, int n)
  210.         {
  211.             string[] lines = File.ReadAllLines(fvd);
  212.             Console.WriteLine(lines[n]);
  213.             int i = 0;
  214.             foreach(string line in lines)
  215.             {
  216.                 if (i != n)
  217.                 {
  218.                     Console.WriteLine(line);
  219.                 }
  220.                 i++;
  221.             }
  222.         }
  223.  
  224.     }
  225. }
  226. a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement