Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. using System;
  2. class MainClass
  3. {
  4. public static void Main(string[] args)
  5. {
  6. Console.WriteLine("請輸入一個1至9的正整數");
  7. int a = Convert.ToInt32(Console.ReadLine());
  8. Console.WriteLine("請輸入一串大寫字母");
  9. string b = Console.ReadLine();
  10.  
  11. 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" };
  12. Console.Write("輸出:");
  13. string str = generate(a, b, label);
  14. Console.WriteLine(str);
  15. }
  16. public static string generate(int num, string b, string[] label)
  17. {
  18. string str="";
  19. for (int i = 0; i < b.Length; i++)
  20. {
  21. for (int j = 0; j < label.Length; j++)
  22. {
  23. if (b[i].ToString() == label[j])
  24. {
  25. if (j + num <= 26)
  26. {
  27. str = str+label[j + num];
  28. }
  29. else if (j + num > 26)
  30. {
  31. str = str+label[j + num - 26];
  32. }
  33. }
  34. }
  35. }
  36. return str;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement