【洛谷OJ】【JAVA】P1914 小書童——密碼
阿新 • • 發佈:2019-02-05
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(); } }