Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://docs.google.com/spreadsheets/d/1ifpSwWnQq30W3RupjK05vlIFAB8JPVqpp7Xcjg5Ed9Q/edit#gid=305617494
- //https://drive.google.com/file/d/1zztnRw9Ou-W_CPLm9WYbFgH7riDYJgFo/view
- //КРОТОВ СЕРГЕЙ КБ11СО 11.10.21
- using System;
- using System.Collections.Generic;
- class HelloWorld
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int[] a = new int[n];
- int i = 0, j = n - 1, now = 0;
- while(i <= j) {
- now = int.Parse(Console.ReadLine());
- if (now >= 0)
- a[i++] = now;
- else
- a[j--] = now;
- }
- Array.Reverse(a, i, n - i);
- for (j = 0; j < n; j++)
- Console.WriteLine(" " + a[j]);
- Console.ReadKey();
- }
- }
- using System;
- using System.Collections.Generic;
- class HelloWorld
- {
- static void rem(ref int[] a, int st, int en)
- {
- if(st >= 0 && en < a.Length) { // 1 2 3 4 5
- Console.WriteLine(" Vrem " + st + " " + en);
- int[] b = (int[])a.Clone();// 1 2 3
- Array.Resize(ref a, a.Length - (en - st + 1));//
- for(int i = en + 1; i < b.Length; i++) {
- a[i - (en - st + 1)] = b[i];
- }
- }
- }
- static void ins(ref int[] a, int st, int elem)
- {
- ins(ref a, st, new int[] { elem });
- }
- static void ins(ref int[] a, int st, int[] elem)
- {
- if (st >= 0)
- {
- Console.WriteLine(" Vins " + st + " " + elem.Length);
- int[] b = (int[])a.Clone();
- Array.Resize(ref a, a.Length + elem.Length);
- for (int i = st; i < b.Length; i++)
- {
- a[i + elem.Length] = b[i];
- }
- for(int i = 0; i < elem.Length; i++)
- {
- a[i + st] = elem[i];
- }
- }
- }
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int[] a = new int[n];
- int[] mima = new int[] { 0, int.MaxValue, 0, 0}; //minindex minlen maxindex maxlen
- int len = 1;
- for (int i = 0; i < n; i++) {
- a[i] = int.Parse(Console.ReadLine());
- if (i == 0) continue;
- //len += (a[i - 1] == a[i]) ? 1 : (-len + 1); //len++ : len = 1
- if (a[i - 1] != a[i])
- {
- if (mima[1] > len)
- {
- mima[1] = len;
- mima[0] = i - 1;
- }
- if (mima[3] <= len)
- {
- mima[3] = len;
- mima[2] = i - 1;
- }
- len = 1;
- } else {
- len++;
- }
- }
- if (mima[1] > len)
- {
- mima[1] = len;
- mima[0] = n - 1;
- }
- if (mima[3] <= len)
- {
- mima[3] = len;
- mima[2] = n - 1;
- }
- //a = new int[n]; //1 2 2 4 5
- //for (int i = 1; i <= n; i++)
- // a[i-1] = i;
- int[] m = new int[mima[1]];
- for(int i = mima[0] - mima[1] + 1; i <= mima[0]; i++)
- {
- m[i - mima[0] + mima[1] - 1] = a[i];
- Console.WriteLine(" > " + a[i]);
- }
- int[] ma = new int[mima[3]];
- for (int i = mima[2] - mima[3] + 1; i <= mima[2]; i++)
- {
- ma[i - mima[2] + mima[3] - 1] = a[i];
- Console.WriteLine(" >>> " + a[i]);
- }
- int[] toCompare = (int[])a.Clone();
- rem(ref a, mima[0] - mima[1] + 1, mima[0]); //
- ins(ref a, mima[0] - mima[1] + 1, ma); //ma.Length
- int dif = ma.Length - mima[1];
- rem(ref a, mima[2] - mima[3] + 1 + dif, mima[2] + dif);
- ins(ref a, mima[2] - mima[3] + 1 + dif, m);
- for (int i = 0; i < a.Length; i++)
- Console.WriteLine(a[i] + " VS " + toCompare[i]);
- Console.ReadKey();
- /*
- 14
- 1
- 1
- 2
- 2
- 3
- 4
- 5
- 5
- 5
- 6
- 6
- 6
- 7
- 7
- 3
- 1
- 2
- 2
- 2
- 1
- 2
- */
- }
- }
- using System;
- using System.IO;
- class HelloWorld
- {
- static int[] insar(int n, bool file = false)
- {
- int[] a = new int[n];
- for(int i = 0; i < n; i++)
- {
- if (file)
- a[i] = int.Parse(sr.ReadLine());
- else
- a[i] = int.Parse(Console.ReadLine());
- }
- return a;
- }
- static int[] num = new int[2] {1, 1};
- static int[] exp(int[] a, bool write = false)
- {
- if (write)
- sw.WriteLine("Export #{0}", num[0]++);
- else
- Console.WriteLine("Export #{0}", num[1]++);
- for (int i = 0; i < a.Length; i++)
- {
- if (write)
- sw.WriteLine(a[i]);
- else
- Console.WriteLine(a[i]);
- }
- return a;
- }
- static void remElem(ref int[] Y, int index)
- {
- rem(ref Y, index, index);
- }
- static void rem(ref int[] a, int st, int en)
- {
- if(st >= 0 && en < a.Length) { // 1 2 3 4 5
- Console.WriteLine(" Vrem " + st + " " + en);
- int[] b = (int[])a.Clone();// 1 2 3
- Array.Resize(ref a, a.Length - (en - st + 1));//
- for(int i = en + 1; i < b.Length; i++) {
- a[i - (en - st + 1)] = b[i];
- }
- }
- }
- static void addElem(ref int[] Y, int elem)
- {
- ins(ref Y, Y.Length, elem);
- }
- static void ins(ref int[] a, int st, int elem)
- {
- ins(ref a, st, new int[] { elem });
- }
- static void ins(ref int[] a, int st, int[] elem)
- {
- if (st >= 0)
- {
- Console.WriteLine(" Vins " + st + " " + elem.Length);
- int[] b = (int[])a.Clone();
- Array.Resize(ref a, a.Length + elem.Length);
- for (int i = st; i < b.Length; i++)
- {
- a[i + elem.Length] = b[i];
- }
- for(int i = 0; i < elem.Length; i++)
- {
- a[i + st] = elem[i];
- }
- }
- }
- static StreamWriter sw = new StreamWriter("C:/inpu/out.txt", true);
- static StreamReader sr = new StreamReader("C:/inpu/in.txt");
- static bool isPow(int x) { //представляется ли число в виде a^p где a, p > 1
- for(int i = 2; i <= Math.Sqrt(x); i++) {
- int y = x;
- bool ret = true;
- while(y > 0) {
- if (y % i == 0 || y == 1) {
- y /= i;
- } else {
- ret = false;
- break;
- }
- }
- if (ret)
- return true;
- }
- return false;
- }
- static int[] findminchet(int[] X)
- {
- int minchet = int.MaxValue;
- for (int i = 0; i < X.Length; i++)
- {
- if (X[i] % 2 == 0 && X[i] < minchet)
- minchet = X[i];
- }
- int[] lis = new int[0];
- for (int i = 0; i < X.Length; i++)
- {
- if (X[i] == minchet)
- addElem(ref lis, i);
- }
- return lis;
- }
- static void Main()
- {
- //StreamReader sr = new StreamReader("C:/inpu/in.txt");
- //StreamWriter sw = new StreamWriter("C:/inpu/out.txt", true);
- int n = int.Parse(sr.ReadLine());
- int[] X = insar(n, true); //input array
- int[] Y = new int[0];
- //int minchet = int.MaxValue;
- for (int i = 0; i < n; i++)
- {
- if (isPow(X[i]))
- addElem(ref Y, X[i]);
- //if (X[i] % 2 == 0 && X[i] < minchet)
- // minchet = X[i];
- }
- int[] minchet = findminchet(X);
- for(int i = minchet.Length - 1; i >= 0; i--) {
- remElem(ref X, minchet[i]);
- }
- minchet = findminchet(Y);
- for (int i = minchet.Length - 1; i >= 0; i--)
- {
- remElem(ref Y, minchet[i]);
- }
- exp(X, true); //export array
- exp(Y, true); //export array
- exp(X); //export array
- exp(Y); //export array
- sw.Close(); //Закрываем поток, очищаем буфер, сохраняем в файл
- Console.ReadKey();
- /*
- 20
- 1
- 1
- 2
- 2
- 3
- 3
- 4
- 4
- 5
- 5
- 6
- 6
- 7
- 7
- 8
- 8
- 9
- 9
- 10
- 10
- */
- }
- }
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- class HelloWorld {
- static string Format00(int x) {
- return ((x.ToString()).Length == 1) ? ("0" + x.ToString()) : x.ToString();
- }
- /*
- * sort:
- * 0 - none
- * 1 - asc
- * 2 - desc
- */
- const string path = "C:/inpu/";
- 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) {
- if (Directory.Exists(path + NameSet))
- return false;
- if (N > 100)
- return false;
- Random rnd = new Random();
- for (int i = 0; i < N; i++) {
- //repeat
- //sort
- //Type
- int tests = rnd.Next(LenMin, LenMax);
- double[] toput = new double[tests];
- if (Repeat) {
- for (int j = 0; j < tests; j++) {
- toput[j] = Type == "int" ? rnd.Next(Min, Max) : (rnd.Next(Min * 100, Max * 100) / 100.0);
- }
- //List<int> res = new List<int>(numbers);
- } else {
- //Dictionary<int, bool> numbers = new Dictionary<int, bool>();
- //foreach (var pair in numbers.OrderBy(pair => pair.Value))
- //{
- // Console.WriteLine("{0} - {1}", pair.Key, pair.Value);
- //}
- //List sortedList = new ArrayList(yourHashSet);
- //Collections.sort(sortedList);
- //numbers = (numbers.OrderBy(key => key.Key)).ToDictionary(key => key.Key, key => key.Value);
- //List<int> hList = hset.ToList();
- HashSet<double> numbers = new HashSet<double>();
- while (numbers.Count < tests) {
- numbers.Add(Type == "int" ? rnd.Next(Min, Max) : (rnd.Next(Min * 100, Max * 100) / 100.0));
- }
- List<double> numm = new List<double>(numbers);
- for (int j = 0; j < tests; j++) {
- toput[j] = numm[j];
- }
- }
- if (sort != "none")
- Array.Sort(toput);
- if (sort == "desc")
- Array.Reverse(toput);
- //StreamReader sr = new StreamReader("C:/inpu/in.txt");
- Directory.CreateDirectory(path + NameSet);
- StreamWriter sw = new StreamWriter(path + NameSet +"/test" + Format00(i + 1) + ".txt", true);
- sw.WriteLine(tests);
- for (int j = 0; j < tests; j++) {
- if (row)
- sw.Write((Type == "int" ? (int)toput[j] : toput[j]) + " ");
- else
- sw.WriteLine(Type == "int" ? (int)toput[j] : toput[j]);
- }
- sw.Close();
- }
- return true;
- }
- static void Main() {
- //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
- createTests("Long test", 10, "double", -100000, 100000, 5, 90, false, "none", false);
- //createTests("baaa", 4, "int", 2, 10, 4, 10, false, "desc", true);
- //createTests("rrbaaa", 4, "int", 2, 10, 4, 10, true, "none", true);
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement