Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MainClass
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("請輸入一個1至9的正整數");
- int a = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("請輸入一串大寫字母");
- string b = Console.ReadLine();
- string[] label = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
- Console.Write("輸出:");
- string str = generate(a, b, label);
- Console.WriteLine(str);
- }
- public static string generate(int num, string b, string[] label)
- {
- string str="";
- for (int i = 0; i < b.Length; i++)
- {
- for (int j = 0; j < label.Length; j++)
- {
- if (b[i].ToString() == label[j])
- {
- if (j + num <= 26)
- {
- str = str+label[j + num];
- }
- else if (j + num > 26)
- {
- str = str+label[j + num - 26];
- }
- }
- }
- }
- return str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement