Advertisement
Pearlfromsu

Untitled

Dec 26th, 2021
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. class HelloWorld {
  6.  
  7.     static string Format00(int x) {
  8.         return ((x.ToString()).Length == 1) ? ("0" + x.ToString()) : x.ToString();
  9.     }
  10.     /*
  11.      * sort:
  12.      *      0 - none
  13.      *      1 - asc
  14.      *      2 - desc
  15.      */
  16.     const string path = "C:/inpu/";
  17.     static bool createTests(string NameSet, int N = 2, string Type = "int", int Min = 2, int Max = 10, int LenMin = 4, int LenMax = 10, bool Repeat = true, string sort = "none", bool row = false) {
  18.         if (Directory.Exists(path + NameSet))
  19.             return false;
  20.         if (N > 100)
  21.             return false;
  22.         Random rnd = new Random();
  23.         for (int i = 0; i < N; i++) {
  24.  
  25.             //repeat
  26.             //sort
  27.             //Type
  28.             int tests = rnd.Next(LenMin, LenMax);
  29.             double[] toput = new double[tests];
  30.             if (Repeat) {
  31.                 for (int j = 0; j < tests; j++) {
  32.                     toput[j] = Type == "int" ? rnd.Next(Min, Max) : (rnd.Next(Min * 100, Max * 100) / 100.0);
  33.                 }
  34.  
  35.                 //List<int> res = new List<int>(numbers);
  36.  
  37.             } else {
  38.                 //Dictionary<int, bool> numbers = new Dictionary<int, bool>();
  39.                 //foreach (var pair in numbers.OrderBy(pair => pair.Value))
  40.                 //{
  41.                 //    Console.WriteLine("{0} - {1}", pair.Key, pair.Value);
  42.                 //}
  43.                 //List sortedList = new ArrayList(yourHashSet);
  44.                 //Collections.sort(sortedList);
  45.                 //numbers = (numbers.OrderBy(key => key.Key)).ToDictionary(key => key.Key, key => key.Value);
  46.                 //List<int> hList = hset.ToList();
  47.  
  48.                 HashSet<double> numbers = new HashSet<double>();
  49.                 while (numbers.Count < tests) {
  50.                     numbers.Add(Type == "int" ? rnd.Next(Min, Max) : (rnd.Next(Min * 100, Max * 100) / 100.0));
  51.                 }
  52.                 List<double> numm = new List<double>(numbers);
  53.                 for (int j = 0; j < tests; j++) {
  54.                     toput[j] = numm[j];
  55.                 }
  56.             }
  57.             if (sort != "none")
  58.                 Array.Sort(toput);
  59.             if (sort == "desc")
  60.                 Array.Reverse(toput);
  61.  
  62.             //StreamReader sr = new StreamReader("C:/inpu/in.txt");
  63.             Directory.CreateDirectory(path + NameSet);
  64.             StreamWriter sw = new StreamWriter(path + NameSet +"/test" + Format00(i + 1) + ".txt", true);
  65.             sw.WriteLine(tests);
  66.             for (int j = 0; j < tests; j++) {
  67.                 if (row)
  68.                     sw.Write((Type == "int" ? (int)toput[j] : toput[j]) + " ");
  69.                 else
  70.                     sw.WriteLine(Type == "int" ? (int)toput[j] : toput[j]);
  71.             }
  72.             sw.Close();
  73.         }
  74.         return true;
  75.     }
  76.     static void Main() {
  77.         //NameSet, int N = 2, string Type = "int", int Min = 2, int Max = 10, int LenMin = 4, int LenMax = 10, bool Repeat = true, string sort = "none", bool row = false
  78.         createTests("Long test", 10, "double", -100000, 100000, 5, 90, false, "none", false);
  79.         //createTests("baaa", 4, "int", 2, 10, 4, 10, false, "desc", true);
  80.         //createTests("rrbaaa", 4, "int", 2, 10, 4, 10, true, "none", true);
  81.         Console.ReadKey();
  82.     }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement