Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
90
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.  
  3. class MainClass
  4. {
  5. public static void Main(string[] args)
  6. {
  7. Console.WriteLine("輸入一個1至9的正整數");
  8. int q = Int32.Parse(Console.ReadLine());
  9. Console.WriteLine("輸入一串英文字母");
  10. string w = Console.ReadLine();
  11. Console.WriteLine(ASC(q,w));
  12. }
  13. public static string ASC(int q, string w)
  14. {
  15. string k="";
  16. for(int i=0;i<w.Length;i++)
  17. {
  18. int ascii = Convert.ToInt32(w[i]);
  19. if(ascii>=65 && ascii<=90)
  20. {
  21. ascii=ascii+q;
  22. if(ascii>90)
  23. {
  24. ascii=ascii-25;
  25. }
  26. char ch = Convert.ToChar(ascii);
  27. string ch1=ch.ToString();
  28. k=k+ch1;
  29. }
  30. if(ascii>=97 && ascii<=122)
  31. {
  32. ascii=ascii+q;
  33. if(ascii>122){
  34. ascii=ascii-25;
  35. }
  36. char ch = Convert.ToChar(ascii);
  37. string ch1=ch.ToString();
  38. k=k+ch1;
  39. }
  40. }
  41. return k;
  42. }
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement