Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- namespace lab66oop
- {
- class Program
- {
- static void Main1(string[] args)
- {
- try
- {
- string path = @"C:\Users\ПК\Desktop\Ilsaf\ООП\test.txt";
- StreamReader readpath = new StreamReader(path);
- string text = readpath.ReadToEnd();
- Console.WriteLine(text);
- text = text.Replace("0", "ноль");
- text = text.Replace("1", "один");
- text = text.Replace("2", "два");
- text = text.Replace("3", "три");
- text = text.Replace("4", "четыре");
- text = text.Replace("5", "пять");
- text = text.Replace("6", "шесть");
- text = text.Replace("7", "семь");
- text = text.Replace("8", "восемь");
- text = text.Replace("9", "девять");
- Console.WriteLine(text);
- }
- catch
- {
- Console.WriteLine("Указан неверный путь к файлу!");
- }
- }
- }
- class Program2
- {
- static void Main(string[] args)
- {
- try
- {
- string PathInput = @"C:\Users\ПК\Desktop\Ilsaf\ООП\books.txt";
- string PathOutput = @"C:\Users\ПК\Desktop\Ilsaf\ООП\sorted.txt";
- StreamReader ReadPathIn = new StreamReader(PathInput, System.Text.Encoding.Default);
- //StreamWriter WritePathIn = new StreamWriter(PathOutput, false,System.Text.Encoding.Default);
- FileInfo writePathIN = new FileInfo(PathOutput);
- string str = ReadPathIn.ReadToEnd();
- string[] arr = str.Split();
- List<string> genres = new List<string>();
- //HashSet<string> genres = new HashSet<string>();
- int janrind = 0;
- for(int i = 0; i < arr.Length; i++) // заполнение списка жанров
- {
- if (arr[i].Contains("жанр"))
- {
- janrind = i;
- genres.Add(arr[janrind + 1]);
- }
- }
- foreach(var i in genres)
- {
- Console.Write(i + "\n");
- }
- for(int i = 0; i < genres.Count; i++) // удаление повторяющихся жанров
- {
- int counter = 0;
- for (int j = 0; j < genres.Count; j++)
- {
- if (genres[i] == genres[j])
- {
- counter += 1;
- if (counter > 1)
- {
- genres.RemoveAt(j);
- }
- //genres.RemoveAt(i + 1);
- }
- }
- }
- string outputString = "";
- for(int i = 0; i < genres.Count; i++)
- {
- int c = 0;
- foreach(var j in arr)
- {
- if (genres[i] == j)
- {
- c += 1;
- }
- }
- //WritePathIn.Write(c + " " +genres[i]);
- //File.WriteAllText(PathOutput, c + " " + genres[i] + "\n");
- string.Join(outputString, c + " " + genres[i] + "\n");
- }
- File.WriteAllText(PathOutput, outputString);
- //WritePathIn.Write("awdw");
- //Console.WriteLine(outputString);
- /*(foreach (var i in genres)
- {
- Console.Write(i + "\n");
- }*/
- //Console.WriteLine(string.Join("", arr));
- }
- catch
- {
- Console.WriteLine("Указан неверный путь к файлу!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement