1. 程式人生 > >【洛谷OJ】【JAVA】P1914 小書童——密碼

【洛谷OJ】【JAVA】P1914 小書童——密碼

import java.util.Scanner;

public class Main {
	private static Scanner cin;

	public static void main(String args[]) throws Exception {
		cin = new Scanner(System.in);
		int n = cin.nextInt();
		n = n % (122-97+1);
		String password = cin.next();
		char[] array = password.toCharArray();
		char[] ret = new char[array.length];
		int length = 0;
		for(int i=0; i<array.length;i++) {
			if(array[i] >= 97 && array[i]<=122) {
				if(array[i]+n >122) {
					ret[length] = (char)(array[i]+n-122+97-1);
				}else {
					ret[length] = (char)(array[i]+n);
				}
				length++;
			}
		}
		for(int i=0;i<length;i++) {
			System.out.print(ret[i]); 
		}
		System.out.println();
	}
	
}