Advertisement
Pearlfromsu

Untitled

Oct 12th, 2021
1,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.37 KB | None | 0 0
  1.  
  2. //https://docs.google.com/spreadsheets/d/1ifpSwWnQq30W3RupjK05vlIFAB8JPVqpp7Xcjg5Ed9Q/edit#gid=305617494
  3. //https://drive.google.com/file/d/1zztnRw9Ou-W_CPLm9WYbFgH7riDYJgFo/view
  4.  
  5. //КРОТОВ СЕРГЕЙ КБ11СО 11.10.21
  6. using System;
  7. using System.Collections.Generic;
  8. class HelloWorld
  9. {
  10.     static void Main()
  11.     {
  12.         int n = int.Parse(Console.ReadLine());
  13.         int[] a = new int[n];
  14.         int i = 0, j = n - 1, now = 0;
  15.         while(i <= j) {
  16.             now = int.Parse(Console.ReadLine());
  17.             if (now >= 0)
  18.                 a[i++] = now;
  19.             else
  20.                 a[j--] = now;
  21.         }
  22.         Array.Reverse(a, i, n - i);
  23.         for (j = 0; j < n; j++)
  24.             Console.WriteLine(" " + a[j]);
  25.  
  26.         Console.ReadKey();
  27.     }
  28. }
  29.  
  30.  
  31.  
  32.  
  33. using System;
  34. using System.Collections.Generic;
  35. class HelloWorld
  36. {
  37.    
  38.     static void rem(ref int[] a, int st, int en)
  39.     {
  40.         if(st >= 0 && en < a.Length) { //                   1 2 3 4 5
  41.             Console.WriteLine(" Vrem " + st + " " + en);
  42.             int[] b = (int[])a.Clone();//                   1 2 3
  43.             Array.Resize(ref a, a.Length - (en - st + 1));//
  44.             for(int i = en + 1; i < b.Length; i++) {
  45.                 a[i - (en - st + 1)] = b[i];
  46.             }
  47.         }
  48.     }
  49.     static void ins(ref int[] a, int st, int elem)
  50.     {
  51.         ins(ref a, st, new int[] { elem });
  52.     }
  53.     static void ins(ref int[] a, int st, int[] elem)
  54.     {
  55.         if (st >= 0)
  56.         {
  57.             Console.WriteLine(" Vins " + st + " " + elem.Length);
  58.             int[] b = (int[])a.Clone();
  59.  
  60.             Array.Resize(ref a, a.Length + elem.Length);
  61.            
  62.             for (int i = st; i < b.Length; i++)
  63.             {
  64.                 a[i + elem.Length] = b[i];
  65.             }
  66.             for(int i = 0; i < elem.Length; i++)
  67.             {
  68.                 a[i + st] = elem[i];
  69.             }
  70.         }
  71.     }
  72.  
  73.     static void Main()
  74.     {
  75.         int n = int.Parse(Console.ReadLine());
  76.         int[] a = new int[n];
  77.         int[] mima = new int[] { 0, int.MaxValue, 0, 0}; //minindex minlen maxindex maxlen
  78.         int len = 1;
  79.         for (int i = 0; i < n; i++) {
  80.             a[i] = int.Parse(Console.ReadLine());
  81.             if (i == 0) continue;
  82.             //len += (a[i - 1] == a[i]) ? 1 : (-len + 1); //len++ : len = 1
  83.             if (a[i - 1] != a[i])
  84.             {
  85.                 if (mima[1] > len)
  86.                 {
  87.                     mima[1] = len;
  88.                     mima[0] = i - 1;
  89.                 }
  90.                 if (mima[3] <= len)
  91.                 {
  92.                     mima[3] = len;
  93.                     mima[2] = i - 1;
  94.                 }
  95.                 len = 1;
  96.             } else {
  97.                 len++;
  98.             }
  99.         }
  100.         if (mima[1] > len)
  101.         {
  102.             mima[1] = len;
  103.             mima[0] = n - 1;
  104.         }
  105.         if (mima[3] <= len)
  106.         {
  107.             mima[3] = len;
  108.             mima[2] = n - 1;
  109.         }
  110.  
  111.  
  112.  
  113.         //a = new int[n]; //1 2 2 4 5
  114.         //for (int i = 1; i <= n; i++)
  115.         //    a[i-1] = i;
  116.         int[] m = new int[mima[1]];
  117.         for(int i = mima[0] - mima[1] + 1; i <= mima[0]; i++)
  118.         {
  119.             m[i - mima[0] + mima[1] - 1] = a[i];
  120.             Console.WriteLine(" > " + a[i]);
  121.         }
  122.  
  123.         int[] ma = new int[mima[3]];
  124.         for (int i = mima[2] - mima[3] + 1; i <= mima[2]; i++)
  125.         {
  126.             ma[i - mima[2] + mima[3] - 1] = a[i];
  127.             Console.WriteLine(" >>> " + a[i]);
  128.         }
  129.  
  130.         int[] toCompare = (int[])a.Clone();
  131.         rem(ref a, mima[0] - mima[1] + 1, mima[0]); //
  132.         ins(ref a, mima[0] - mima[1] + 1, ma); //ma.Length
  133.  
  134.         int dif = ma.Length - mima[1];
  135.  
  136.         rem(ref a, mima[2] - mima[3] + 1 + dif, mima[2] + dif);
  137.         ins(ref a, mima[2] - mima[3] + 1 + dif, m);
  138.  
  139.         for (int i = 0; i < a.Length; i++)
  140.             Console.WriteLine(a[i] + " VS " + toCompare[i]);
  141.  
  142.         Console.ReadKey();
  143.         /*
  144. 14
  145. 1
  146. 1
  147. 2
  148. 2
  149. 3
  150. 4
  151. 5
  152. 5
  153. 5
  154. 6
  155. 6
  156. 6
  157. 7
  158. 7
  159.  
  160.  
  161. 3
  162. 1
  163. 2
  164. 2
  165.  
  166.  
  167. 2
  168. 1
  169. 2
  170.          */
  171.     }
  172. }
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194. using System;
  195. using System.IO;
  196. class HelloWorld
  197. {
  198.     static int[] insar(int n, bool file = false)
  199.     {
  200.         int[] a = new int[n];
  201.         for(int i = 0; i < n; i++)
  202.         {
  203.             if (file)
  204.                 a[i] = int.Parse(sr.ReadLine());
  205.             else
  206.                 a[i] = int.Parse(Console.ReadLine());
  207.         }
  208.         return a;
  209.     }
  210.  
  211.     static int[] num = new int[2] {1, 1};
  212.  
  213.     static int[] exp(int[] a, bool write = false)
  214.     {
  215.         if (write)
  216.             sw.WriteLine("Export #{0}", num[0]++);
  217.         else
  218.             Console.WriteLine("Export #{0}", num[1]++);
  219.         for (int i = 0; i < a.Length; i++)
  220.         {
  221.             if (write)
  222.                 sw.WriteLine(a[i]);
  223.             else
  224.                 Console.WriteLine(a[i]);
  225.         }
  226.         return a;
  227.     }
  228.     static void remElem(ref int[] Y, int index)
  229.     {
  230.         rem(ref Y, index, index);
  231.     }
  232.     static void rem(ref int[] a, int st, int en)
  233.     {
  234.         if(st >= 0 && en < a.Length) { //                   1 2 3 4 5
  235.             Console.WriteLine(" Vrem " + st + " " + en);
  236.             int[] b = (int[])a.Clone();//                   1 2 3
  237.             Array.Resize(ref a, a.Length - (en - st + 1));//
  238.             for(int i = en + 1; i < b.Length; i++) {
  239.                 a[i - (en - st + 1)] = b[i];
  240.             }
  241.         }
  242.     }
  243.     static void addElem(ref int[] Y, int elem)
  244.     {
  245.         ins(ref Y, Y.Length, elem);
  246.     }
  247.     static void ins(ref int[] a, int st, int elem)
  248.     {
  249.         ins(ref a, st, new int[] { elem });
  250.     }
  251.     static void ins(ref int[] a, int st, int[] elem)
  252.     {
  253.         if (st >= 0)
  254.         {
  255.             Console.WriteLine(" Vins " + st + " " + elem.Length);
  256.             int[] b = (int[])a.Clone();
  257.  
  258.             Array.Resize(ref a, a.Length + elem.Length);
  259.            
  260.             for (int i = st; i < b.Length; i++)
  261.             {
  262.                 a[i + elem.Length] = b[i];
  263.             }
  264.             for(int i = 0; i < elem.Length; i++)
  265.             {
  266.                 a[i + st] = elem[i];
  267.             }
  268.         }
  269.     }
  270.     static StreamWriter sw = new StreamWriter("C:/inpu/out.txt", true);
  271.     static StreamReader sr = new StreamReader("C:/inpu/in.txt");
  272.  
  273.     static bool isPow(int x) { //представляется ли число в виде a^p где a, p > 1
  274.         for(int i = 2; i <= Math.Sqrt(x); i++) {
  275.             int y = x;
  276.             bool ret = true;
  277.             while(y > 0) {
  278.                 if (y % i == 0 || y == 1) {
  279.                     y /= i;
  280.                 } else {
  281.                     ret = false;
  282.                     break;
  283.                 }
  284.             }
  285.             if (ret)
  286.                 return true;
  287.         }
  288.         return false;
  289.     }
  290.  
  291.     static int[] findminchet(int[] X)
  292.     {
  293.         int minchet = int.MaxValue;
  294.         for (int i = 0; i < X.Length; i++)
  295.         {
  296.             if (X[i] % 2 == 0 && X[i] < minchet)
  297.                 minchet = X[i];
  298.         }
  299.         int[] lis = new int[0];
  300.         for (int i = 0; i < X.Length; i++)
  301.         {
  302.             if (X[i] == minchet)
  303.                 addElem(ref lis, i);
  304.         }
  305.         return lis;
  306.     }
  307.  
  308.     static void Main()
  309.     {
  310.        
  311.         //StreamReader sr = new StreamReader("C:/inpu/in.txt");
  312.         //StreamWriter sw = new StreamWriter("C:/inpu/out.txt", true);
  313.  
  314.         int n = int.Parse(sr.ReadLine());
  315.         int[] X = insar(n, true); //input array
  316.         int[] Y = new int[0];
  317.  
  318.         //int minchet = int.MaxValue;
  319.         for (int i = 0; i < n; i++)
  320.         {
  321.             if (isPow(X[i]))
  322.                 addElem(ref Y, X[i]);
  323.             //if (X[i] % 2 == 0 && X[i] < minchet)
  324.             //    minchet = X[i];
  325.         }
  326.  
  327.         int[] minchet = findminchet(X);
  328.         for(int i = minchet.Length - 1; i >= 0; i--) {
  329.             remElem(ref X, minchet[i]);
  330.         }
  331.         minchet = findminchet(Y);
  332.         for (int i = minchet.Length - 1; i >= 0; i--)
  333.         {
  334.             remElem(ref Y, minchet[i]);
  335.         }
  336.  
  337.         exp(X, true); //export array
  338.         exp(Y, true); //export array
  339.         exp(X); //export array
  340.         exp(Y); //export array
  341.  
  342.         sw.Close(); //Закрываем поток, очищаем буфер, сохраняем в файл
  343.         Console.ReadKey();
  344.         /*
  345. 20
  346. 1
  347. 1
  348. 2
  349. 2
  350. 3
  351. 3
  352. 4
  353. 4
  354. 5
  355. 5
  356. 6
  357. 6
  358. 7
  359. 7
  360. 8
  361. 8
  362. 9
  363. 9
  364. 10
  365. 10
  366.          */
  367.     }
  368. }
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405. using System;
  406. using System.Collections.Generic;
  407. using System.IO;
  408. using System.Linq;
  409. class HelloWorld {
  410.  
  411.     static string Format00(int x) {
  412.         return ((x.ToString()).Length == 1) ? ("0" + x.ToString()) : x.ToString();
  413.     }
  414.     /*
  415.      * sort:
  416.      *      0 - none
  417.      *      1 - asc
  418.      *      2 - desc
  419.      */
  420.     const string path = "C:/inpu/";
  421.     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) {
  422.         if (Directory.Exists(path + NameSet))
  423.             return false;
  424.         if (N > 100)
  425.             return false;
  426.         Random rnd = new Random();
  427.         for (int i = 0; i < N; i++) {
  428.  
  429.             //repeat
  430.             //sort
  431.             //Type
  432.             int tests = rnd.Next(LenMin, LenMax);
  433.             double[] toput = new double[tests];
  434.             if (Repeat) {
  435.                 for (int j = 0; j < tests; j++) {
  436.                     toput[j] = Type == "int" ? rnd.Next(Min, Max) : (rnd.Next(Min * 100, Max * 100) / 100.0);
  437.                 }
  438.  
  439.                 //List<int> res = new List<int>(numbers);
  440.  
  441.             } else {
  442.                 //Dictionary<int, bool> numbers = new Dictionary<int, bool>();
  443.                 //foreach (var pair in numbers.OrderBy(pair => pair.Value))
  444.                 //{
  445.                 //    Console.WriteLine("{0} - {1}", pair.Key, pair.Value);
  446.                 //}
  447.                 //List sortedList = new ArrayList(yourHashSet);
  448.                 //Collections.sort(sortedList);
  449.                 //numbers = (numbers.OrderBy(key => key.Key)).ToDictionary(key => key.Key, key => key.Value);
  450.                 //List<int> hList = hset.ToList();
  451.  
  452.                 HashSet<double> numbers = new HashSet<double>();
  453.                 while (numbers.Count < tests) {
  454.                     numbers.Add(Type == "int" ? rnd.Next(Min, Max) : (rnd.Next(Min * 100, Max * 100) / 100.0));
  455.                 }
  456.                 List<double> numm = new List<double>(numbers);
  457.                 for (int j = 0; j < tests; j++) {
  458.                     toput[j] = numm[j];
  459.                 }
  460.             }
  461.             if (sort != "none")
  462.                 Array.Sort(toput);
  463.             if (sort == "desc")
  464.                 Array.Reverse(toput);
  465.  
  466.             //StreamReader sr = new StreamReader("C:/inpu/in.txt");
  467.             Directory.CreateDirectory(path + NameSet);
  468.             StreamWriter sw = new StreamWriter(path + NameSet +"/test" + Format00(i + 1) + ".txt", true);
  469.             sw.WriteLine(tests);
  470.             for (int j = 0; j < tests; j++) {
  471.                 if (row)
  472.                     sw.Write((Type == "int" ? (int)toput[j] : toput[j]) + " ");
  473.                 else
  474.                     sw.WriteLine(Type == "int" ? (int)toput[j] : toput[j]);
  475.             }
  476.             sw.Close();
  477.         }
  478.         return true;
  479.     }
  480.     static void Main() {
  481.         //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
  482.         createTests("Long test", 10, "double", -100000, 100000, 5, 90, false, "none", false);
  483.         //createTests("baaa", 4, "int", 2, 10, 4, 10, false, "desc", true);
  484.         //createTests("rrbaaa", 4, "int", 2, 10, 4, 10, true, "none", true);
  485.         Console.ReadKey();
  486.     }
  487. }
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement