andy6804tw
7/18/2016 - 5:30 AM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=8311 這題字串旋轉就是把輸入的五個數字加起來就是我們所想要的位移數,需要考慮兩個地方 1.假如位移數超過26就要取她的餘數 2.若小於0就要進入迴圈

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=8311

這題字串旋轉就是把輸入的五個數字加起來就是我們所想要的位移數,需要考慮兩個地方 1.假如位移數超過26就要取她的餘數 2.若小於0就要進入迴圈每次加26到大於0為止

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		String str = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; //先存入字串,防止益位故2次a~z
		char arr[] = str.toCharArray();//拆開成字元陣列
		while (scn.hasNext()) {
			int tot = 0, n;
			for (int i = 0; i < 5; i++) {
				n = scn.nextInt();
				tot += n;
			}
			while (tot < 0) {
				tot += 26;
			}
			if (tot > 26)
				tot %= 26;
			for (int i = tot; i < tot + 26; i++)
				System.out.print(arr[i]);
			System.out.println();

		}
	}
		/* 
    題目:[C_ST58-易] 字串旋轉
    作者:1010
    時間:西元 2016 年 7 月 */
}