CODE FESTIVAL 2016 qual A

Submission #1221146

Source codeソースコード

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		String string = cin.next();
		int K = cin.nextInt();
		//贪心算法的最佳体现
		int i;
		for (i=0;i<string.length()-1;i++){
			//最后一个字符要单独处理
			char c = string.charAt(i);
			if (c == 'a') {
				System.out.print('a');
				continue;
			}
			if (K < 'z' - c + 1) {
				System.out.print(c);
				continue;
			}
			System.out.print('a');
			K -= 'z' - c + 1;
		}
		K %= 26;
		char c = string.charAt(i);
		if (K >= 'z' - c + 1) {
			System.out.print((char)('a' + (K - 'z' + c -1 ) % 26));
		} else {
			System.out.print( (char)(c + K));
		}
	}
}

Submission

Task問題 C - 次のアルファベット / Next Letter
User nameユーザ名 kelvinlu
Created time投稿日時
Language言語 Java8 (OpenJDK 1.8.0)
Status状態 AC
Score得点 400
Source lengthソースコード長 732 Byte
File nameファイル名
Exec time実行時間 471 ms
Memory usageメモリ使用量 35796 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt
All 400 / 400 0_00.txt,0_01.txt,0_02.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt,1_11.txt,1_12.txt,1_13.txt,1_14.txt,1_15.txt,1_16.txt,1_17.txt,1_18.txt,1_19.txt,1_20.txt,1_21.txt,1_22.txt,1_23.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 164 ms 22228 KB
0_01.txt AC 90 ms 19924 KB
0_02.txt AC 92 ms 18900 KB
1_00.txt AC 91 ms 16972 KB
1_01.txt AC 91 ms 21332 KB
1_02.txt AC 91 ms 21588 KB
1_03.txt AC 90 ms 20564 KB
1_04.txt AC 91 ms 21844 KB
1_05.txt AC 90 ms 21332 KB
1_06.txt AC 422 ms 35408 KB
1_07.txt AC 433 ms 32388 KB
1_08.txt AC 427 ms 35416 KB
1_09.txt AC 414 ms 30980 KB
1_10.txt AC 415 ms 31256 KB
1_11.txt AC 410 ms 32376 KB
1_12.txt AC 411 ms 32400 KB
1_13.txt AC 400 ms 35192 KB
1_14.txt AC 414 ms 33668 KB
1_15.txt AC 428 ms 31136 KB
1_16.txt AC 416 ms 33676 KB
1_17.txt AC 412 ms 32964 KB
1_18.txt AC 421 ms 33716 KB
1_19.txt AC 427 ms 33668 KB
1_20.txt AC 418 ms 31628 KB
1_21.txt AC 424 ms 32260 KB
1_22.txt AC 433 ms 35796 KB
1_23.txt AC 471 ms 32384 KB