Java洛谷P1914 小书童——密码
程序员文章站
2022-07-13 11:58:33
...
题目链接:https://www.luogu.com.cn/problem/P1914
代码实例:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String str = scanner.next();
char a[] = new char[str.length()];
for (int i = 0; i < str.length(); i++) {
if(n==26) {
a[i] = str.charAt(i);
}
if(str.charAt(i)+n>'z' && n!=26) {
a[i] = (char) ('a'-1+(n-('z'-str.charAt(i))));
}
if(str.charAt(i)+n<='z' && n!=26) {
a[i] = (char) (str.charAt(i)+n);
}
System.out.print(a[i]);
}
scanner.close();
}
}