1. 程式人生 > >Java複習之物聯網期末考試243 - 字串加密

Java複習之物聯網期末考試243 - 字串加密

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();
	}
}