Advertisement
Guest User

lab3

a guest
Dec 6th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace ConsoleApp12
  9. {
  10. public class Work
  11. {
  12. public string name;
  13. public int a;
  14. public int b;
  15.  
  16. public Work(string name, int a, int b)
  17. {
  18. this.name = name;
  19. this.a = a;
  20. this.b = b;
  21. }
  22. }
  23.  
  24. class Program
  25. {
  26. static void Main(string[] args)
  27. {
  28.  
  29. StreamReader str = new StreamReader("input.txt");
  30. string[] lines = str.ReadToEnd().Split('\n');
  31. int count = lines.Length;
  32.  
  33. LinkedList<Work> works = new LinkedList<Work>();
  34.  
  35. for (int i = 0; i < count; i++)
  36. {
  37. string name = lines[i].Split(' ')[0];
  38. int a = int.Parse(lines[i].Split(' ')[1]);
  39. int b = int.Parse(lines[i].Split(' ')[2]);
  40.  
  41. if (i == 0)
  42. works.AddFirst(new Work(name, a, b));
  43. else
  44. {
  45. var current = works.First;
  46. for (int j = 0; j < works.Count; j++)
  47. {
  48.  
  49. int t1 = Math.Min(a, current.Value.b);
  50. int t2 = Math.Min(current.Value.a, b);
  51. if (t1 < t2)
  52. {
  53. works.AddBefore(current, new Work(name, a, b));
  54. break;
  55. }
  56. else
  57. {
  58. if (current.Next == null)
  59. {
  60. works.AddAfter(current, new Work(name, a, b));
  61. break;
  62. }
  63. current = current.Next;
  64. }
  65.  
  66. }
  67.  
  68. }
  69.  
  70. }
  71.  
  72. int time = works.First.Value.a;
  73. int endfirst = 0;
  74. int startsecond = time;
  75. foreach (Work current in works)
  76. {
  77.  
  78. endfirst += current.a;
  79. if (endfirst > startsecond)
  80. {
  81. time += endfirst - startsecond;
  82. startsecond = endfirst;
  83. }
  84. startsecond += current.b;
  85. time += current.b;
  86. Console.Write(current.name + " ");
  87. }
  88. Console.WriteLine();
  89. Console.WriteLine(time);
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement