Advertisement
joekatona

C# vegyes.txt + feldolgozó program

Apr 25th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. vegyes.txt
  2. 120;IPv4;Router
  3. 180;192;20
  4. Switch;88;35
  5. IPv6;38;2
  6.  
  7.  
  8. using System;
  9. using System.IO;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14.  
  15. namespace vegyes
  16. {
  17. class Program
  18. {
  19. static void Main(string[] args)
  20. {
  21. List<int> szamok = new List<int>();
  22. List<string> szavak = new List<string>();
  23.  
  24. string[] sorok = File.ReadAllLines("vegyes.txt");
  25.  
  26. foreach (var sor in sorok)
  27. {
  28. string[] adatok = sor.Split(';');
  29.  
  30. foreach (var adat in adatok)
  31. {
  32. try
  33. {
  34. int sz = int.Parse(adat);
  35. szamok.Add( sz );
  36. }
  37. catch (Exception)
  38. {
  39. szavak.Add(adat);
  40. }
  41. }
  42. }
  43.  
  44. Console.WriteLine("Szavak:");
  45. foreach (var szo in szavak)
  46. {
  47. Console.WriteLine( " "+szo );
  48. }
  49.  
  50. Console.WriteLine();
  51. Console.WriteLine("Számok:");
  52. Console.WriteLine(" Összeg: "+szamok.Sum());
  53. Console.WriteLine(" Minimum: "+szamok.Min());
  54. Console.WriteLine(" Maximum: "+szamok.Max());
  55. Console.WriteLine(" Átlag: "+Math.Round( szamok.Average(),2) );
  56.  
  57. szamok.Sort();
  58.  
  59. Console.Write("Sorrendben: ");
  60. foreach (var sz in szamok)
  61. {
  62. Console.Write( sz+" " );
  63. }
  64.  
  65.  
  66. Console.ReadKey();
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement