swattw

Untitled

Nov 1st, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication4
  8. {
  9.  
  10.  
  11. class Program
  12. {
  13.  
  14.  
  15. static void Main(string[] args)
  16. {
  17. int x, f, c;
  18. String s;
  19. String D;
  20.  
  21.  
  22.  
  23.  
  24. while (true) //毫無反應,就是個迴圈
  25. {
  26. x = Int32.Parse(Console.ReadLine()); //位移量
  27. if (x == 0) { break; }
  28. x = x % 26; //避免位移過大
  29. f = Int32.Parse(Console.ReadLine()); //功能
  30. c = Int32.Parse(Console.ReadLine()); //行數
  31. //char[] msg_c = "\0".ToCharArray();
  32.  
  33.  
  34. for (int i = 0; i < c; i++)//第一行→第二行
  35. {
  36. s = Console.ReadLine();
  37. char[] eng_char = { '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' }; //字元表
  38. char[] eng_char_b = { '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' };//字元表 大寫
  39. int a;
  40. char[] msg_c = s.ToCharArray();//轉換陣列
  41.  
  42.  
  43. if (f == 1)
  44. {
  45. for (int j = 0; j < s.Length; j++)
  46. {
  47. if (Array.IndexOf(eng_char, msg_c[j]) != -1) //是小寫
  48. {
  49. msg_c[j] = eng_char[(Array.IndexOf(eng_char, msg_c[j]) + x) % 26];
  50. }
  51. else if (Array.IndexOf(eng_char_b, msg_c[j]) != -1) //是大寫
  52. {
  53. msg_c[j] = eng_char_b[(Array.IndexOf(eng_char_b, msg_c[j]) + x) % 26];
  54. }
  55. else
  56. {
  57. msg_c[j] = msg_c[j];
  58.  
  59. }
  60.  
  61.  
  62.  
  63. }
  64.  
  65. }
  66. else if (f == 2)
  67. {
  68. x = 26 - (x % 26); //左移
  69. for (int j = 0; j < s.Length; j++)
  70. {
  71. if (Array.IndexOf(eng_char, msg_c[j]) != -1) //是小寫
  72. {
  73. msg_c[j] = eng_char[(Array.IndexOf(eng_char, msg_c[j]) + x) % 26];
  74. }
  75. else if (Array.IndexOf(eng_char_b, msg_c[j]) != -1) //是大寫
  76. {
  77. msg_c[j] = eng_char_b[(Array.IndexOf(eng_char_b, msg_c[j]) + x) % 26];
  78. }
  79. else
  80. {
  81. msg_c[j] = msg_c[j];
  82.  
  83. }
  84. }
  85. }
  86.  
  87. D = new string(msg_c);
  88. Console.WriteLine(D);
  89. }
  90.  
  91.  
  92.  
  93. }
  94. }
  95.  
  96. }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment