Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace DecimalNumber
- {
- class Program
- {
- static bool f(UInt64 n)
- {
- var a = new UInt16[10];
- var b = new UInt16[10];
- a[9] = Convert.ToUInt16(n % 10);
- a[8] = Convert.ToUInt16(n % 100 / 10);
- a[7] = Convert.ToUInt16(n % 1000 / 100);
- a[6] = Convert.ToUInt16(n % 10000 / 1000);
- a[5] = Convert.ToUInt16(n % 100000 / 10000);
- a[4] = Convert.ToUInt16(n % 1000000 / 100000);
- a[3] = Convert.ToUInt16(n % 10000000 / 1000000);
- a[2] = Convert.ToUInt16(n % 100000000 / 10000000);
- a[1] = Convert.ToUInt16(n % 1000000000 / 100000000);
- a[0] = Convert.ToUInt16(n % 10000000000 / 1000000000);
- for (UInt16 i = 0; i <= 9; i++)
- b[a[i]]++;
- if (EqualsArrays(a, b))
- return true;
- else
- return false;
- }
- static bool EqualsArrays(UInt16[] a, UInt16[] b)
- {
- for (UInt16 i = 0; i <= 9; i++)
- if (a[i] != b[i])
- return false;
- return true;
- }
- static bool begin()
- {
- Console.WriteLine("Начать проверку с 1 000 000 000?");
- Console.WriteLine("1 - да");
- Console.WriteLine("2 - нет");
- ConsoleKeyInfo info;
- info = Console.ReadKey();
- Console.WriteLine();
- if (info.KeyChar == '2')
- return false;
- else
- return true;
- }
- static UInt64 InputInt(string name, UInt64 min, UInt64 max) // Возвращает число в заданном диапазоне, введённое пользователем
- {
- bool correct = false;
- bool first = true;
- UInt64 temp = 0;
- Console.Write(name + " = ");
- do
- {
- if (first)
- first = false;
- else
- Console.Write("Некорректно введено число. Повторите ввод:\n" + name + " = ");
- try
- {
- correct = true;
- temp = UInt64.Parse(Console.ReadLine());
- }
- catch (FormatException) { correct = false; }
- catch (OverflowException) { correct = false; }
- if (correct)
- if (temp < min || temp > max)
- correct = false;
- }
- while (!correct);
- return temp;
- }
- static void Main(string[] args)
- {
- UInt64 min;
- if (begin())
- min = 1000000000;
- else
- min = InputInt("min",
- 1000000000,
- 9999999999);
- for (UInt64 n = min; n < 10000000000; n++)
- {
- if (f(n))
- {
- Console.WriteLine("--------> " + n);
- StreamWriter sw;
- FileInfo fi = new FileInfo("numbers.txt");
- sw = fi.AppendText();
- sw.WriteLine(n + "\n");
- sw.Close();
- }
- else
- if (n % 100000 == 0)
- Console.WriteLine(n);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment