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 q = Int32.Parse(Console.ReadLine());
- Console.WriteLine("輸入一串英文字母");
- string w = Console.ReadLine();
- Console.WriteLine(ASC(q,w));
- }
- public static string ASC(int q, string w)
- {
- string k="";
- for(int i=0;i<w.Length;i++)
- {
- int ascii = Convert.ToInt32(w[i]);
- if(ascii>=65 && ascii<=90)
- {
- ascii=ascii+q;
- if(ascii>90)
- {
- ascii=ascii-25;
- }
- char ch = Convert.ToChar(ascii);
- string ch1=ch.ToString();
- k=k+ch1;
- }
- if(ascii>=97 && ascii<=122)
- {
- ascii=ascii+q;
- if(ascii>122){
- ascii=ascii-25;
- }
- char ch = Convert.ToChar(ascii);
- string ch1=ch.ToString();
- k=k+ch1;
- }
- }
- return k;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement