小鑫の日常系列故事(七)——小纸条

小鑫の日常系列故事(七)——小纸条

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

小鑫在高中的时候喜欢上了一个十分漂亮的女孩。那个女孩也很喜欢他,就答应成为他的女朋友。

但是大家都知道高中的生活是忙碌的,除了上课就是上课,有时候可能连课间时间都被老师占用。于是小鑫想出了在上课给女朋友传纸条的方法来表达自己的爱慕。

又但是她与小鑫之间的距离太远,中间必须通过同学来传递纸条。可他们并不想让同学们知道写的什么就想到加密纸条这种方法。方法如下:

他们每天都会约定加密常数n,举个例子,当n=1时,今天写的每一句话中所用的字母都会向后+1,比如:i love you就成了j mpwf zpv ,当然了当是z的时候,+1就等于a。

请你帮他女朋友解密他写的纸条么?

Input

输入为多组,每组为两行。

第一行为n,-50<n<50

第二行为一句话,只有小写字母和空格。长度小于10000

Output

 输出解密之后的内容

Sample Input

1
j mpwf zpv

Sample Output

i love you

Hint

Source

lin

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace test1
{
    class Program
    {
        static void Main(string[] args)
        {          
            string q;
            char[] a = new char[10001];
            while((q = Console.ReadLine())!=string.Empty)
            {
                string s = Console.ReadLine();
                int n =int.Parse(q);
                a = s.ToCharArray();
                int k = n % 26;
                for (int i = 0; i < a.Length; i++)
                {                   
                    //Console.WriteLine(m);
                    if (a[i] != ' ') 
                    {
                        int m = a[i] - k;
                        if (m < 'a')
                        {
                            a[i] = Convert.ToChar('z' + 1 - ('a' - m));
                        }
                        else if (m > 'z')
                        {
                            a[i] = Convert.ToChar('a' - 1 + (m - 'z'));
                        }
                        else
                            a[i] = Convert.ToChar(m);
                    }
                }
                Console.WriteLine(a);
            }
            

        }
    }
}

猜你喜欢

转载自blog.csdn.net/feissss/article/details/82948734