Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication4
- {
- class Program
- {
- static void Main(string[] args)
- {
- int x, f, c;
- String s;
- String D;
- while (true) //毫無反應,就是個迴圈
- {
- x = Int32.Parse(Console.ReadLine()); //位移量
- if (x == 0) { break; }
- x = x % 26; //避免位移過大
- f = Int32.Parse(Console.ReadLine()); //功能
- c = Int32.Parse(Console.ReadLine()); //行數
- //char[] msg_c = "\0".ToCharArray();
- for (int i = 0; i < c; i++)//第一行→第二行
- {
- s = Console.ReadLine();
- 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' }; //字元表
- 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' };//字元表 大寫
- int a;
- char[] msg_c = s.ToCharArray();//轉換陣列
- if (f == 1)
- {
- for (int j = 0; j < s.Length; j++)
- {
- if (Array.IndexOf(eng_char, msg_c[j]) != -1) //是小寫
- {
- msg_c[j] = eng_char[(Array.IndexOf(eng_char, msg_c[j]) + x) % 26];
- }
- else if (Array.IndexOf(eng_char_b, msg_c[j]) != -1) //是大寫
- {
- msg_c[j] = eng_char_b[(Array.IndexOf(eng_char_b, msg_c[j]) + x) % 26];
- }
- else
- {
- msg_c[j] = msg_c[j];
- }
- }
- }
- else if (f == 2)
- {
- x = 26 - (x % 26); //左移
- for (int j = 0; j < s.Length; j++)
- {
- if (Array.IndexOf(eng_char, msg_c[j]) != -1) //是小寫
- {
- msg_c[j] = eng_char[(Array.IndexOf(eng_char, msg_c[j]) + x) % 26];
- }
- else if (Array.IndexOf(eng_char_b, msg_c[j]) != -1) //是大寫
- {
- msg_c[j] = eng_char_b[(Array.IndexOf(eng_char_b, msg_c[j]) + x) % 26];
- }
- else
- {
- msg_c[j] = msg_c[j];
- }
- }
- }
- D = new string(msg_c);
- Console.WriteLine(D);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment