回覆列表
  • 1 # 使用者1093589836191

    Console.WriteLine("請輸入一個字串!");

    string sString = Console.ReadLine();

    StringBuilder a = new StringBuilder();

    for (int i = sString.Length - 1; i >= 0; i--)

    {

    a.Append(sString[i]);

    }

    if (sString.Equals(a.ToString()))

    Console.WriteLine("是迴文");

    else

    Console.WriteLine("不是迴文");

    Console.ReadLine();

    2.直接在單個字串裡面進行處理,透過比較

    Console.WriteLine("請輸入一個字串!");

    string s = Console.ReadLine();

    int half = s.Length / 2;

    int len = s.Length;

    for (int i = 0; i < half; i++)

    {

    if (s[i] != s[len - i - 1])

    {

    Console.WriteLine("Congratulations,It is not a palindrome");

    return;

    }

    }

    Console.WriteLine("Sorry,It is a palindrome");

    3.先求出整數上各位置的數字,有點白痴。。。

    int a = 123456789;

    int b=1;

    int d=a/10;

    while (d!= 0)

    {

    d = d / 10;

    b++;//位數

    }

    int[] array = new int[b];

    for(int c=b;c>0;c--)

    {

    array[c-1] = a /Convert.ToInt32((Math.Pow(Convert.ToDouble(10), Convert.ToDouble(c-1)))) ;

    a = a % Convert.ToInt32((Math.Pow(Convert.ToDouble(10), Convert.ToDouble(c - 1))));

    Console.WriteLine(array[c-1].ToString());

    }

  • 中秋節和大豐收的關聯?
  • 房頂裂開,漏水.怎麼補漏水?