Parcourir la source

checkDiameter

Андрей Морозов il y a 2 ans
Parent
commit
14ee1133e0
2 fichiers modifiés avec 34 ajouts et 7 suppressions
  1. 33 6
      Exam/Program.cs
  2. 1 1
      Exam/ReadData.cs

+ 33 - 6
Exam/Program.cs

@@ -12,24 +12,51 @@ namespace Exam
             public bool isDefective, isReinforced;
         }
 
-        Tubes[] tube = new Tubes[0];
-
         static void Main(string[] args)
         {
             Tubes[] tube = new Tubes[0];
-            tube = ReadData.Read("data.txt", ref tube);
+            tube = ReadData.Read("data.txt", tube);
+
+            
 
-            double[] diameters = new double[] { 20, 25, 32, 40, 50, 63 };
+            double[] diameters = new double[] { 20.000, 25.000, 32.000, 40.000, 50.000, 63.000 };
 
             for (int i = 0; i < tube.Length; i++)
             {
-                if (!(3960 <= tube[i].length && tube[i].length >= 4040))
+                if (!(3960 <= tube[i].length && tube[i].length <= 4040))
                 {
                     tube[i].isDefective = true;
                 }
             }
 
-            
+            double startRange, endRange;
+            for (int i = 0; i < tube.Length; i++)
+            {
+                bool check = true;
+                if (!tube[i].isDefective)
+                {
+                    for (int j = 0; j < diameters.Length; j++)
+                    {
+                        startRange = diameters[j] - (diameters[j] / 100.0);
+                        endRange = diameters[j] + (diameters[j] / 100.0);
+                        if (!(startRange <= tube[i].diameter && tube[i].diameter <= endRange))
+                        {
+                            check = false;
+                            Console.WriteLine(i + 1 + " " + startRange + " " + endRange);
+                        }
+                        else
+                        {
+                            check = true;
+                            Console.WriteLine(i + 1 + " " + startRange + " " + endRange);
+                            break;
+                        }
+                    }
+                    if (!check)
+                    {
+                        tube[i].isDefective = true;
+                    }
+                }
+            }
         }
     }
 }

+ 1 - 1
Exam/ReadData.cs

@@ -9,7 +9,7 @@ namespace Exam
 {
     internal class ReadData
     {
-        static public program.Tubes[] Read(string path, ref program.Tubes[] arr)
+        static public program.Tubes[] Read(string path, program.Tubes[] arr)
         {
             if (!File.Exists(path))
             {