- using ConsoleApp1;
- using System;//程式庫呼叫
- using System.ComponentModel.DataAnnotations;
- using System.Linq.Expressions;
- using ABC.qq;
- class Program//負責一部分工作的人
- {
- static void Main()//method ..Entry Point 程式進入點
- {
-
- try
- {
- string str=Console.ReadLine();
- if(str.Trim()=="")
- {
- throw new Exception();
- }
- if (str.Length == 1)
- str = encrypt(str[0]).ToString();
- else
- {
- str = encrypt(str[0]) + str.Substring(1, str.Length - 2) + encrypt(str[str.Length-1]);
- }
- Console.WriteLine(str);
- }
- catch
- {
- Console.WriteLine("error");
- }
- }
- static char encrypt(char ch)
- {
- if (ch >= '0' && ch <= '8')
- ch++;
- else if (ch == '9')
- ch = '0';
- else if (Char.IsUpper(ch))//判斷是否為大寫
- {
- ch=(char)(Char.ToLower(ch)+1);//轉小寫後加1
- }
- else if (Char.IsLower(ch))//判斷是否為小寫
- {
- ch=(char)(Char.ToUpper(ch)+1);//轉大寫後加1
- }
- else
- {
- throw new Exception("unexpected char: " + ch);
- }
- return ch;
- }
- }
複製代碼 |