Advertisement
kasper_k

lab62

Nov 1st, 2022
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.26 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. namespace lab66oop
  5. {
  6.     class Program
  7.     {
  8.         static void Main1(string[] args)
  9.         {
  10.             try
  11.             {
  12.                 string path = @"C:\Users\ПК\Desktop\Ilsaf\ООП\test.txt";
  13.                 StreamReader readpath = new StreamReader(path);
  14.                 string text = readpath.ReadToEnd();
  15.                 Console.WriteLine(text);
  16.                 text = text.Replace("0", "ноль");
  17.                 text = text.Replace("1", "один");
  18.                 text = text.Replace("2", "два");
  19.                 text = text.Replace("3", "три");
  20.                 text = text.Replace("4", "четыре");
  21.                 text = text.Replace("5", "пять");
  22.                 text = text.Replace("6", "шесть");
  23.                 text = text.Replace("7", "семь");
  24.                 text = text.Replace("8", "восемь");
  25.                 text = text.Replace("9", "девять");
  26.                 Console.WriteLine(text);
  27.             }
  28.             catch
  29.             {
  30.                 Console.WriteLine("Указан неверный путь к файлу!");
  31.             }
  32.         }
  33.     }
  34.     class Program2
  35.     {
  36.         static void Main(string[] args)
  37.         {
  38.             try
  39.             {
  40.                 string PathInput = @"C:\Users\ПК\Desktop\Ilsaf\ООП\books.txt";
  41.                 string PathOutput = @"C:\Users\ПК\Desktop\Ilsaf\ООП\sorted.txt";
  42.                 StreamReader ReadPathIn = new StreamReader(PathInput, System.Text.Encoding.Default);
  43.                 //StreamWriter WritePathIn = new StreamWriter(PathOutput, false,System.Text.Encoding.Default);
  44.                 FileInfo writePathIN = new FileInfo(PathOutput);
  45.                 string str = ReadPathIn.ReadToEnd();
  46.                 string[] arr = str.Split();
  47.                 List<string> genres = new List<string>();
  48.                 //HashSet<string> genres = new HashSet<string>();
  49.                 int janrind = 0;
  50.                 for(int i = 0; i < arr.Length; i++) // заполнение списка жанров
  51.                 {
  52.                     if (arr[i].Contains("жанр"))
  53.                     {
  54.                         janrind = i;
  55.                         genres.Add(arr[janrind + 1]);
  56.                     }                            
  57.                 }
  58.                 foreach(var i in genres)
  59.                 {
  60.                     Console.Write(i + "\n");
  61.                 }
  62.                 for(int i = 0; i < genres.Count; i++) // удаление повторяющихся жанров
  63.                 {
  64.                     int counter = 0;
  65.                     for (int j = 0; j < genres.Count; j++)
  66.                     {
  67.                         if (genres[i] == genres[j])
  68.                         {
  69.                             counter += 1;
  70.                             if (counter > 1)
  71.                             {
  72.                                 genres.RemoveAt(j);
  73.                             }
  74.                             //genres.RemoveAt(i + 1);
  75.                         }
  76.                     }                    
  77.                 }
  78.                 string outputString = "";
  79.                 for(int i = 0; i < genres.Count; i++)
  80.                 {
  81.                     int c = 0;
  82.                     foreach(var j in arr)
  83.                     {
  84.                         if (genres[i] == j)
  85.                         {
  86.                             c += 1;
  87.                         }
  88.                     }
  89.                     //WritePathIn.Write(c + " " +genres[i]);
  90.                     //File.WriteAllText(PathOutput, c + " " + genres[i] + "\n");
  91.                     string.Join(outputString, c + " " + genres[i] + "\n");
  92.                 }
  93.                 File.WriteAllText(PathOutput, outputString);
  94.                 //WritePathIn.Write("awdw");
  95.                 //Console.WriteLine(outputString);
  96.                 /*(foreach (var i in genres)
  97.                 {
  98.                     Console.Write(i + "\n");
  99.                 }*/
  100.                 //Console.WriteLine(string.Join("", arr));
  101.             }
  102.             catch
  103.             {
  104.                 Console.WriteLine("Указан неверный путь к файлу!");
  105.             }
  106.         }
  107.        
  108.     }
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement