Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace ConsoleApp2
- {
- class Program
- {
- const string CFd = "duomenys.txt";
- const string CFr = "rez.txt";
- static void Main(string[] args)
- {
- string sep = " ,./`-:;()?!";
- string zod;
- string zod2;
- int me = 0;
- int me2 = 0;
- RastiZTekste(CFd, sep, out zod, ref me);
- Console.WriteLine("{0} {1}", zod , me+1);
- // PerkeltiEilute(CFd, CFd, me);
- RastiZTtekste(CFd, sep, out zod2, ref me2);
- Console.WriteLine("{0} {1}", zod2, me2 + 1);
- IstryntiTZodi(CFd, zod2, sep, CFr);
- }
- static int SkirtLygSk(string e)
- {
- int kiek = 0;
- char[] lyginiai = { '2', '4', '6', '8' };
- for(int i = 0; i < lyginiai.Length; i++)
- {
- if(e.IndexOf(lyginiai[i]) >= 0)
- {
- kiek++;
- }
- }
- return kiek;
- }
- static int SkirtBalsiuSkaicius(string e)
- {
- int kiek = 0;
- string b = "aAeEiIoOyYUu";
- char[] balses = b.ToCharArray();
- for (int i = 0; i < balses.Length; i++)
- {
- if(e.IndexOf(balses[i]) >= 0)
- {
- kiek++;
- }
- }
- return kiek;
- }
- //static void IstryntiTZodi(string fvd, string zod2, string sep, string fvr)
- //{
- // using (StreamReader reader = new StreamReader(fvd))
- // {
- // string eilute;
- // using (var fr = File.CreateText(fvr))
- // {
- // while ((eilute = reader.ReadLine()) != null)
- // {
- // char[] sk = sep.ToCharArray();
- // string[] parts = eilute.Split(sk, StringSplitOptions.RemoveEmptyEntries);
- // int pr = 0;
- // string z;
- // foreach (string zod in parts)
- // {
- // pr = zod.IndexOf(zod2);
- // if (pr >= 0)
- // {
- // fr.Write("{0}", zod.Remove(pr));
- // }
- // else
- // {
- // fr.Write(" {0}", zod);
- // }
- // }
- // fr.WriteLine();
- // }
- // }
- // }
- //}
- static void IstryntiTZodi(string fvd, string zod2, string sep, string fvr)
- {
- string eilute;
- char[] sk = sep.ToCharArray();
- using (StreamReader reader = new StreamReader(fvd))
- {
- int pr = 0;
- while ((eilute = reader.ReadLine())!=null)
- {
- string[] parts = eilute.Split(sk, StringSplitOptions.RemoveEmptyEntries);
- foreach (string zod in parts)
- {
- pr = zod.IndexOf(zod2);
- if (pr>=0)
- {
- Console.Write("{0}", zod.Remove(pr));
- }
- else
- {
- Console.Write(" {0}", zod);
- }
- }
- Console.WriteLine();
- }
- }
- }
- //static void IstryntiTZodi(string fvd, string zod2, string sep)
- //{
- // char[] s = sep.ToCharArray();
- // string[] lines = File.ReadAllLines(fvd);
- // int i = 0;
- // int pr = 0;
- // foreach(string line in lines)
- // {
- // string[] parts = line.Split(s, StringSplitOptions.RemoveEmptyEntries);
- // pr = parts.IndexOf(zod2);
- // Console.WriteLine(pr);
- // if(pr >=0)
- // {
- // Console.WriteLine("{0}", line.Remove(pr));
- // }
- // else
- // {
- // Console.WriteLine(line);
- // }
- // i++;
- // }
- //}
- static string RastiTZodiEil(string e, string sk)
- {
- char[] sep = sk.ToCharArray();
- string[] parts = e.Split(sep, StringSplitOptions.RemoveEmptyEntries);
- int trump = int.MaxValue;
- string trumpiausias = "";
- foreach(string zod in parts)
- {
- if(zod.Length<trump && SkirtBalsiuSkaicius(zod) == 3)
- {
- trumpiausias = zod;
- trump = zod.Length;
- }
- }
- return trumpiausias;
- }
- static void RastiZTtekste(string fv, string sk, out string zod, ref int me)
- {
- string trump="";
- string z = "";
- int tr = int.MaxValue;
- int i = 0;
- using (StreamReader reader = new StreamReader(fv))
- {
- string eilute;
- while ((eilute = reader.ReadLine()) != null)
- {
- trump = RastiTZodiEil(eilute, sk);
- if (trump.Length < tr)
- {
- tr = trump.Length;
- z = trump;
- me = i;
- }
- i++;
- }
- }
- zod = z;
- }
- static string RastiZodiEil(string e, string sk)
- {
- char[] sep = sk.ToCharArray();
- string[] parts = e.Split(sep, StringSplitOptions.RemoveEmptyEntries);
- string ilgiausias = "";
- foreach(string zod in parts)
- {
- if(zod.Length > ilgiausias.Length && SkirtBalsiuSkaicius(zod) == 3)
- {
- ilgiausias = zod;
- }
- }
- return ilgiausias;
- }
- static void RastiZTekste(string fv, string sk, out string zod, ref int me)
- {
- string z;
- string eilute;
- string ilgiausias = "";
- int i = 0;
- using(StreamReader reader = new StreamReader(fv))
- {
- while((eilute = reader.ReadLine()) != null)
- {
- z = RastiZodiEil(eilute, sk);
- if(z.Length > ilgiausias.Length)
- {
- ilgiausias = z;
- me = i;
- }
- i++;
- }
- }
- zod = ilgiausias;
- }
- static void PerkeltiEilute(string fvd, string fvr, int n)
- {
- string[] lines = File.ReadAllLines(fvd);
- Console.WriteLine(lines[n]);
- int i = 0;
- foreach(string line in lines)
- {
- if (i != n)
- {
- Console.WriteLine(line);
- }
- i++;
- }
- }
- }
- }
- a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement