243 - 字符串加密
Time Limit: 1000 Memory Limit: 65535
Submit: 225 Solved: 231
Description
尝试构造一种自定义的字符串加密方式,首先该字符串的长度对5求余加1作为种子数字,以该种子数字为间隔,获取原字符串的子字符序列,该序列求逆得到最终的序列。
Input
原字符串
Output
加密后的字符串
Sample Input
abcdefghijklmn
Sample Output
kfa
HINT
答案:
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
StringBuilder s2 = new StringBuilder(s1);
int length = s1.length();
int seed = length%5+1;
StringBuilder s3 = new StringBuilder();
for(int i = 0;i < length;i+=seed)
{
s3.append(s2.charAt(i));
}
System.out.print(s3.reverse());
sc.close();
}
}