Пример #1
0
        static void Main(string[] args)
        {
            // Vars
            GlobalVars globalVars     = new GlobalVars();
            int        num_args       = args.Length;
            string     word           = string.Empty;
            string     res_html       = string.Empty;
            string     tmp_message    = string.Empty;
            string     message        = string.Empty;
            string     winner_message = string.Empty;
            string     winner         = string.Empty;
            int        result         = 0;
            int        prev_result    = 0;
            int        tw             = 0;

            int[]    arr_tw    = new int[(num_args * globalVars.arr_se.Length)];    // for total winner
            int[]    arr_tmptw = new int[(num_args * globalVars.arr_se.Length)];    // for total winner
            string[] arr_twe   = new string[(num_args * globalVars.arr_se.Length)]; // for total winner

            //Get the params (words) to do the "for"
            if (num_args == 0)
            {
                Console.WriteLine("Please, type some words to start the search");

                return;
            }

            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Results are listed here:");
            Console.WriteLine("-------------------------------------------------");

            // Get words
            for (int x = 0; x < num_args; x++)
            //for (int x = 0; x < 2; x++)
            {
                word = args[x];

                // Get html from search engines
                int i = 1;

                foreach (string e in globalVars.arr_se)
                {
                    res_html = GetHtml(e, word);

                    // Get Results
                    tmp_message = GetResults(i, res_html);
                    message     = ((i == 1 ? word + " -> " + tmp_message : message + " | " + tmp_message));

                    // Get numbers for comparison
                    result = Convert.ToInt32(tmp_message.Substring(tmp_message.IndexOf(":") + 2));

                    // Save result
                    arr_tw[tw]    = result;
                    arr_tmptw[tw] = result;
                    arr_twe[tw]   = globalVars.arr_namese[(i - 1)];

                    if (i == 2)
                    {
                        Console.WriteLine(message);

                        // Comparing results
                        if (prev_result > result)
                        {
                            winner_message += word + " -> " + globalVars.arr_namese[(i - 2)] + "\n";
                        }
                        else
                        {
                            winner_message += word + " -> " + globalVars.arr_namese[(i - 1)] + "\n";
                        }
                    }

                    prev_result = result;

                    i  += 1;
                    tw += 1;
                }
            }

            // Print winners
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Winners are:");
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine(winner_message.Substring(0, winner_message.Length - 1));
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine("");
            Console.WriteLine("");

            // Get winner
            winner = GetWinner(arr_tw, arr_tmptw, arr_twe);

            Console.WriteLine("The total winner is: {0}", winner);
        }