San-ch

Untitled

Jul 28th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.53 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace DecimalNumber
  5. {
  6.     class Program
  7.     {
  8.         static bool f(UInt64 n)
  9.         {
  10.             var a = new UInt16[10];
  11.             var b = new UInt16[10];
  12.  
  13.             a[9] = Convert.ToUInt16(n % 10);
  14.             a[8] = Convert.ToUInt16(n % 100 / 10);
  15.             a[7] = Convert.ToUInt16(n % 1000 / 100);
  16.             a[6] = Convert.ToUInt16(n % 10000 / 1000);
  17.             a[5] = Convert.ToUInt16(n % 100000 / 10000);
  18.             a[4] = Convert.ToUInt16(n % 1000000 / 100000);
  19.             a[3] = Convert.ToUInt16(n % 10000000 / 1000000);
  20.             a[2] = Convert.ToUInt16(n % 100000000 / 10000000);
  21.             a[1] = Convert.ToUInt16(n % 1000000000 / 100000000);
  22.             a[0] = Convert.ToUInt16(n % 10000000000 / 1000000000);
  23.            
  24.             for (UInt16 i = 0; i <= 9; i++)
  25.                 b[a[i]]++;
  26.  
  27.             if (EqualsArrays(a, b))
  28.                 return true;
  29.             else
  30.                 return false;
  31.         }
  32.  
  33.         static bool EqualsArrays(UInt16[] a, UInt16[] b)
  34.         {
  35.             for (UInt16 i = 0; i <= 9; i++)
  36.                 if (a[i] != b[i])
  37.                     return false;
  38.             return true;
  39.         }
  40.  
  41.         static bool begin()
  42.         {
  43.             Console.WriteLine("Начать проверку с 1 000 000 000?");
  44.             Console.WriteLine("1 - да");
  45.             Console.WriteLine("2 - нет");
  46.             ConsoleKeyInfo info;
  47.             info = Console.ReadKey();
  48.             Console.WriteLine();
  49.             if (info.KeyChar == '2')
  50.                 return false;
  51.             else
  52.                 return true;
  53.         }
  54.  
  55.         static UInt64 InputInt(string name, UInt64 min, UInt64 max) // Возвращает число в заданном диапазоне, введённое пользователем
  56.         {
  57.             bool correct = false;
  58.             bool first = true;
  59.             UInt64 temp = 0;
  60.             Console.Write(name + " = ");
  61.             do
  62.             {
  63.                 if (first)
  64.                     first = false;
  65.                 else
  66.                     Console.Write("Некорректно введено число. Повторите ввод:\n" + name + " = ");
  67.                 try
  68.                 {
  69.                     correct = true;
  70.                     temp = UInt64.Parse(Console.ReadLine());
  71.                 }
  72.                 catch (FormatException) { correct = false; }
  73.                 catch (OverflowException) { correct = false; }
  74.                 if (correct)
  75.                     if (temp < min || temp > max)
  76.                         correct = false;
  77.             }
  78.             while (!correct);
  79.             return temp;
  80.         }
  81.  
  82.         static void Main(string[] args)
  83.         {
  84.             UInt64 min;
  85.             if (begin())
  86.                 min = 1000000000;
  87.             else
  88.                 min = InputInt("min",
  89.                                1000000000,
  90.                                9999999999);
  91.  
  92.             for (UInt64 n = min; n < 10000000000; n++)
  93.             {
  94.                 if (f(n))
  95.                 {
  96.                     Console.WriteLine("--------> " + n);
  97.                     StreamWriter sw;
  98.                     FileInfo fi = new FileInfo("numbers.txt");
  99.                     sw = fi.AppendText();
  100.                     sw.WriteLine(n + "\n");
  101.                     sw.Close();
  102.                 }
  103.                 else
  104.                     if (n % 100000 == 0)
  105.                         Console.WriteLine(n);
  106.             }
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment