返回列表 發帖
  1. using ConsoleApp1;
  2. using System;//程式庫呼叫
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq.Expressions;
  5. using ABC.qq;


  6. class Program//負責一部分工作的人
  7. {
  8.     static void Main()//method ..Entry Point 程式進入點
  9.     {
  10.       
  11.         try
  12.         {
  13.             string str=Console.ReadLine();
  14.             if(str.Trim()=="")
  15.             {
  16.                 throw new Exception();
  17.             }
  18.             if (str.Length == 1)
  19.                 str = encrypt(str[0]).ToString();
  20.             else
  21.             {
  22.                 str = encrypt(str[0]) + str.Substring(1, str.Length - 2) + encrypt(str[str.Length-1]);
  23.             }
  24.             Console.WriteLine(str);
  25.         }
  26.         catch
  27.         {
  28.           Console.WriteLine("error");
  29.         }
  30.     }
  31.     static char encrypt(char ch)
  32.     {
  33.         if (ch >= '0' && ch <= '8')
  34.             ch++;
  35.         else if (ch == '9')
  36.             ch = '0';
  37.         else if (Char.IsUpper(ch))//判斷是否為大寫
  38.         {
  39.             ch=(char)(Char.ToLower(ch)+1);//轉小寫後加1
  40.         }
  41.         else if (Char.IsLower(ch))//判斷是否為小寫
  42.         {
  43.              ch=(char)(Char.ToUpper(ch)+1);//轉大寫後加1
  44.         }
  45.         else
  46.         {
  47.             throw new Exception("unexpected char: " + ch);
  48.         }
  49.         return ch;
  50.     }
  51. }
複製代碼
istak.teach2@gmail.com

TOP

返回列表