[ C# 演算法] 模擬分析指定列印字串

[ C# 演算法] 模擬分析指定列印字串

[ C# 演算法] 模擬分析指定列印字串


 

using System;

using
System.Collections.Generic;

using
System.Linq;

using
System.Text;

 

namespace
CS_Console_printpageAnalytics

{

    class Program

    {

        static void Main(string[]
args)

        {

            int[]
array =
new int[256];

            for
(int m = 0; m < array.Length; m++)

            {

                array[m] = 0;

            }

            String
StrBuf = “1,2,12,15-25,28-100,200-,210-255,13”;//
eJMeA

            Console.WriteLine(eJ±P_oMeA:” + StrBuf);

            ////////////////////////

            //MeAD?TE±P_

            byte[]
array1 =
Encoding.ASCII.GetBytes(StrBuf);

            Boolean
blnRegular = true;

            // Loop
through contents of the array.

            foreach
(byte element in
array1)

            {

                //Console.WriteLine(“{0}
= {1}”, element, (char)element);

                blnRegular = true;

                if
((element >= 48) && (element <= 59))

                {

                    continue;

                }

                if
((element == 45) || (element == 44))

                {

                    continue;

                }

                blnRegular = false;

                break;

            }

            ////////////////////////

            int
intfindCharIndex=-1;

            int
intRangeS, intRangeE;

            if
(blnRegular)

            {

                Console.WriteLine(MeAa!D?T”);

                string[]
strs = StrBuf.Split(
‘,’);//
DyiDXaWCL

 

                for
(int i = 0; i < strs.Length; i++)//
aWCLXjXe

                {

                    intfindCharIndex = -1;

                    intfindCharIndex =
strs[i].IndexOf(
‘-‘);

                    if
(intfindCharIndex >= 0)//
baWCL?±P_O±_¢XXI!CL

                    {

                        string[]
strs1 = strs[i].Split(
‘-‘);

                        intRangeS=-1;

                        intRangeE=-1;

                        for (int j = 0; j <
strs1.Length; j++)
//
¦M±aXI!CLoLaOA

                        {

                            if (j %
2 == 0)

                            {

 

                                intRangeS = Convert.ToInt32(strs1[j], 10);

                            }

                            else

                            {

                                try

                                {

                                    intRangeE =
Convert.ToInt32(strs1[j], 10);

                                }

                                catch

                                {

                                    intRangeE =
-1;

                                }

                                break;

                            }

                        }

                        if (intRangeS > 0 && intRangeE > 0)//CLDXXI!dooO3A

                        {

 

                            if (intRangeS <= intRangeE)

                            {

                                for (int k =
intRangeS; k <= intRangeE; k++)

                                {

                                    Console.Write(k
+
“,”);

                                    if (k <= 256)

                                    {

                                        array[k
– 1] = 1;

                                    }

                                }

                                Console.WriteLine();

                            }

                            else

                            {

                                for (int l =
intRangeE; l <= intRangeS; l++)

                                {

                                    Console.Write(l + “,”);

                                    if (l <= 256)

                                    {

                                        array[l
– 1] = 1;

                                    }

                                }

                                Console.WriteLine();

                            }

                        }

                        else

                        {

                            Console.WriteLine(intRangeS+“,”);

                            if
(intRangeS <= 256)

                            {

                                array[intRangeS
– 1] = 1;

                            }

                        }

                    }

                    else//CLDXa@CLoA

                    {

                        intRangeS = Convert.ToInt32(strs[i], 10);

                        Console.WriteLine(intRangeS + “,”);

                        if (intRangeS <= 255)

                        {

                            array[intRangeS –
1] = 1;

                        }

                    }

                }

            }

            else

            {

                Console.WriteLine(MeAa!u~”);

            }

            Console.WriteLine();

            for
(int n = 0; n < array.Length; n++)

            {

                Console.Write(array[n]
+
“,”);

            }

            //////////////////////////

 

            Pause();

        }

        static void Pause()

        {

            Console.Write(“Press any key to continue . . . “);

            Console.ReadKey(true);

        }

    }

}

 

 

 


發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *