Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- namespace lab5
- {
- class Program
- {
- static int N=0;
- static Random rnd = new Random();
- static int kol = 0;
- static int nmb = 1;
- static void AddL(List<int> list, int n)
- {
- for (int i = 0; i < n; i++)
- {
- list.Add(rnd.Next(0, 10));
- }
- }
- static void PrintL(List<int> list, int n)
- {
- for (int i = 0; i < list.Count; i++)
- {
- Console.Write(list[i] + " ");
- }
- Console.WriteLine();
- }
- static void print_hashset(int i,HashSet<char>[] arr)
- {
- Console.WriteLine($"{i+1}-ю страну посетили:");
- foreach (var val in arr[i])
- {
- Console.Write(val + " ");
- }
- Console.WriteLine();
- }
- static IEnumerable<char> Union(int i, HashSet<char>[] arr, IEnumerable<char> query)
- {
- query = from planet in query.Union(arr[i])
- select planet;
- return query;
- }
- /* public static HashSet<char> ToHashSet<char> (this IEnumerable<char> query)
- {
- HashSet<char> result = new HashSet<char>();
- result.UnionWith(query);
- return result;
- }*/
- static HashSet<char> Intersect(int i, HashSet<char>[] arr, IEnumerable<char> query, HashSet<char> rez)
- {
- query = from planet in query.Intersect(arr[i])
- select planet;
- rez.UnionWith(query);
- foreach (var val in rez)
- {
- Console.Write(val + " ");
- }
- return rez;
- }
- static void prntarr(int i, HashSet<char>[] arr, int quantity)
- {
- if (arr[i].Count == quantity) Console.WriteLine($"{i+1}-ю страну посетили все туристы");
- else if (arr[i].Count == 0) Console.WriteLine($"{i + 1}-ю никто из туристов не посетил");
- else Console.WriteLine($"{i + 1}-ю страну посетили {arr[i].Count} туристов");
- Console.WriteLine();
- }
- static void Write_text(string name) //заполнение файла текстом
- {
- try
- {
- using (StreamWriter f = new StreamWriter(name))
- {
- Console.WriteLine("Введите N");
- string buf = Console.ReadLine();
- int N = int.Parse(buf);
- Console.WriteLine("Заполнение файла");
- for (int i = 1; i <= N; i++)
- {
- buf = Console.ReadLine();
- f.WriteLine(buf);
- }
- }
- }
- catch (IOException e)
- {
- Console.WriteLine("Error:" + e.Message);
- return;
- }
- }
- static void Find_Text(string name, HashSet<char>[] arr1) //чтение из файла
- {
- try
- {
- using (StreamReader f = new StreamReader(name))
- {
- int i = 0;
- string s;
- while ((s = f.ReadLine()) != null && i<10)
- {
- string[] splitLine = s.Split(' ');
- kol += splitLine.Length;
- for (int j = 0; j < splitLine.Length; j++)
- { int k = 0;
- while (k < splitLine[j].Length)
- {
- if ((splitLine[j][k] > 'а' && splitLine[j][k] < 'е') || (splitLine[j][k] >= 'ж' && splitLine[j][k] <= 'з'))
- arr1[i].Add(splitLine[j][k++]);
- else k++;
- }
- i++;
- }
- }
- }
- }
- catch (IOException e)
- {
- Console.WriteLine("Error:" + e.Message);
- return;
- }
- }
- static void Dublicates_HashSet(HashSet<char>[] arr, HashSet<char> rez ) //поиск повторяющихся звонких согласных
- {
- var set = new HashSet<char>();
- for (int i = 0; i < kol; i++)
- {
- foreach (var item in arr[i])
- if (!set.Add(item))
- rez.Add(item);
- }
- }
- static void Write_Text(string name) //заполнение файла текстом
- {
- try
- {
- using (StreamWriter f = new StreamWriter(name))
- {
- Console.WriteLine("Введите N");
- string buf = Console.ReadLine();
- f.WriteLine(buf);
- int N = int.Parse(buf);
- Console.WriteLine("Заполнение файла");
- for (int i = 1; i <= N; i++)
- {
- buf = Console.ReadLine();
- f.WriteLine(buf);
- }
- }
- }
- catch (IOException e)
- {
- Console.WriteLine("Error:" + e.Message);
- return;
- }
- }
- static void Read_Text(string name, Dictionary<string, int> d)
- {
- try
- {
- using (StreamReader f = new StreamReader(name))
- {
- string s;
- s = f.ReadLine();
- N = int.Parse(s);
- while ((s = f.ReadLine()) != null)
- {
- string[] splitLine = s.Split(' ');
- string[] splitline2 = splitLine[2].Split('-');
- string nomber = splitline2[0] + "-" + splitline2[1];
- if (!d.ContainsKey(nomber))
- d.Add(nomber, nmb);
- else { int v = d[nomber]; d[nomber] = v + 1; }
- /* if (nmb != "") if (!nmb.Contains(nomber)) nmb += nomber + " ";
- int nom = int.Parse(splitline2[2]); ;
- Employee e = new Employee(splitLine[0], splitLine[1], nomber, nom);
- d.Add(nom, e);*/
- }
- }
- }
- catch (IOException e)
- {
- Console.WriteLine("Error:" + e.Message);
- return;
- }
- }
- static void Main(string[] args)
- {
- /* List<int> list = new List<int>();
- Console.WriteLine("Введите n");
- string buf = Console.ReadLine();
- int n = int.Parse(buf);
- AddL(list, n);
- PrintL(list, list.Count);
- Console.WriteLine("Введите цифру");
- buf = Console.ReadLine();
- int k = int.Parse(buf);
- list.RemoveAll(x=>x==k);
- PrintL(list, list.Count);
- Console.WriteLine("Введите e");
- buf = Console.ReadLine();
- int e = int.Parse(buf);
- int e1 = list.FindIndex(x => x == e);
- int e2 = list.FindLastIndex(x => x == e);
- if (e2 == e1) e2 = -1;
- if (e1 != -1 && e2 != -1) list.Reverse(e1+1, e2-e1-1);
- else Console.WriteLine("e входит менее двух раз");
- PrintL(list, list.Count);
- Console.WriteLine("Введите количество стран");
- buf = Console.ReadLine();
- n = int.Parse(buf);
- HashSet<char>[] arr = new HashSet<char>[n];
- for(int i=0; i<n; i++)
- { HashSet<char> hs = new HashSet<char>();
- arr[i] = hs;
- }
- for (int i = 0; i < n; i++)
- {
- int k1 = rnd.Next(0, 11);
- for (int j = 0; j < k1; j++)
- {
- char ch = (char)rnd.Next(0x0410, 0x44F);
- arr[i].Add(ch);
- }
- }
- for (int i = 0; i < n; i++)
- {
- print_hashset(i, arr);
- }
- IEnumerable<char> query = from planet in arr[0].Union(arr[1])
- select planet;
- for (int i = 2; i < n; i++)
- {
- query= Union(i, arr, query);
- }
- int quantity = query.Count();
- Console.WriteLine($"Всего туристов:{quantity}");
- for (int i = 0; i < n; i++)
- {
- prntarr(i, arr, quantity);
- }*/
- /* Write_text("Text.dat"); //№4
- HashSet<char>[] arr1 = new HashSet<char>[10];
- for (int i = 0; i < 10; i++)
- {
- HashSet<char> hs = new HashSet<char>();
- arr1[i] = hs;
- }
- Find_Text("Text.dat", arr1);
- for (int i = 0; i < kol; i++)
- {
- print_hashset(i, arr1);
- }
- HashSet<char> rez = new HashSet<char>();
- Dublicates_HashSet(arr1, rez);
- var result = rez.OrderBy(s => s);
- foreach (var val in result)
- {
- Console.Write(val + " ");
- }
- Console.WriteLine();*/
- //№5
- Dictionary<string, int> employee = new Dictionary<string, int>();
- Read_Text("Text_.dat", employee);
- foreach (var val in employee)
- {
- Console.Write($"Работников с номером {val.Key} - {val.Value} штук, в среднем {val.Value/employee.Count}");
- Console.WriteLine();
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement