Java实现 洛谷 P1914 小书童——密码-LMLPHP

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();
} }
05-19 02:06