Exemple #1
0
 public static void Dfs(int n, int[] sample)
 {
     if (n >= 9)
     {
         int[,] ans = new int[9, 9];
         int[] shift = { 0, 3, 6, 7, 4, 1, 2, 5, 8 };
         for (int i = 0; i < 9; i++)
         {
             for (int j = 0; j < 9; j++)
             {
                 ans[i, j] = sample[(j + shift[i]) % 9];
                 //Console.Write("{0} ",ans[i,j] );
             }
             //Console.WriteLine();
         }
         int[,] line = { { 3, 4, 5, 6, 7, 8 }, { 5, 3, 4, 8, 6, 7 } };
         int[,] row  = { { 0, 3, 4, 5, 6, 7, 8 }, { 0, 5, 3, 4, 8, 6, 7 } };
         for (int i = 0; i < 6; i++)
         {
             Suduku.Exchange(ans, line[0, i], line[1, i], true);
             for (int j = 0; j < 6; j++)
             {
                 Suduku.Exchange(ans, row[0, j], row[1, j], false);
                 Suduku.Write_txt(ans);
                 Count.count++;
                 if (Count.count >= Count.maxn)
                 {
                     // File.sw.Flush();
                     File.sw.Close();
                     return;
                 }
             }
         }
     }
     if (Count.count >= Count.maxn)
     {
         return;
     }
     for (int i = 1; i <= 9; i++)
     {
         int j = 0, flag = 0;
         while (j < n)
         {
             if (sample[j] == i)
             {
                 flag = 1;
                 break;
             }
             j++;
         }
         if (flag == 0)
         {
             sample[n] = i;
             //Console.WriteLine("{0} {1}",Count.count,Count.maxn);
             Dfs(n + 1, sample);
         }
     }
 }
Exemple #2
0
 static void Main(string[] args)
 {
     System.Diagnostics.Stopwatch runtime = new System.Diagnostics.Stopwatch();
     runtime.Start();
     int[] Line = new int[9];
     Line[0] = 4;
     char[] str = new char[5];
     Count.maxn = Convert.ToInt32(Console.ReadLine());
     Suduku.Dfs(1, Line);
     runtime.Stop();
     Console.WriteLine("{0}", runtime.Elapsed.TotalMilliseconds);
     Console.ReadKey();
 }
Exemple #3
0
        static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch runtime = new System.Diagnostics.Stopwatch();
            runtime.Start();
            string str;
            System.Console.WriteLine("parameter count = {0}", args.Length);

            for (int i = 0; i < args.Length; i++)
            {
                System.Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
            }
            if(args.Length>0)
            {
                Console.ReadLine();
                if (String.Compare(args[0], "-c") == 0)
                {
                    str = args[1];
                    foreach (char i in str)
                        if (i >= '0' && i <= '9') continue;
                        else
                        {
                            Console.Write("Wrong input! Please input correct interger!\n");
                            str = Get_num();
                            break;
                        }
                    int[] Line = new int[9];
                    Line[0] = 4;

                    Count.maxn = Convert.ToInt32(str);
                    Suduku.Dfs(1, Line);
                }

                else if (String.Compare(args[0], "-s") == 0)
                {
                    str = args[1];
                    Console.WriteLine("hihi");
                    suduku_find_answer.suduku_find_answer.Get_read(str);
                }
            }
            else
            {
                int temp = Console.Read();
                if(temp=='0')
                {
                    str = Console.ReadLine();
                    foreach (char i in str)
                        if (i >= '0' && i <= '9') continue;
                        else
                        {
                            Console.Write("Wrong input! Please input correct interger!\n");
                            str = Get_num();
                            break;
                        }
                    int[] Line = new int[9];
                    Line[0] = 4;

                    Count.maxn = Convert.ToInt32(str);
                    Suduku.Dfs(1, Line);
                }
                else
                {
                    str = "out_put.txt";
                    Console.WriteLine("hihi");
                    suduku_find_answer.suduku_find_answer.Get_read(str);
                }
                
            }
            Console.ReadKey();
        }