Submission #24090080


Source Code Expand

import java.util.*;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String answer = "";
		int k = Integer.parseInt(sc.next());

		// 各文字について
		for (int i = 0; i < s.length(); i++) {

			// i文字目を'a'にできるならする
			if (s.charAt(i) != 'a' && 'z' - s.charAt(i) + 1 <= k) {
				answer += "a";
				k -= 'z' - s.charAt(i) + 1;
			} else {
				answer += s.charAt(i) + "";
			}

		}

		// 確認用
//		System.out.println(k);
//		System.out.println(answer);

		// 余ったkを使って最後の文字を循環させる
		k %= 26;
		char x = answer.charAt(answer.length() - 1);
		for (int i = 0; i < k; i++) {
			if (x == 'z') {
				x = 'a';
			} else {
				x++;
			}
		}

		System.out.println(answer.substring(0, answer.length() - 1) + x);

	}
}

Submission Info

Submission Time
Task C - Next Letter
User tobi00604
Language Java (OpenJDK 11.0.6)
Score 400
Code Size 908 Byte
Status AC
Exec Time 882 ms
Memory 58616 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 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
Case Name Status Exec Time Memory
0_00.txt AC 176 ms 39116 KiB
0_01.txt AC 155 ms 38488 KiB
0_02.txt AC 176 ms 39028 KiB
1_00.txt AC 157 ms 38588 KiB
1_01.txt AC 165 ms 38916 KiB
1_02.txt AC 151 ms 38528 KiB
1_03.txt AC 161 ms 38984 KiB
1_04.txt AC 145 ms 38696 KiB
1_05.txt AC 169 ms 39140 KiB
1_06.txt AC 855 ms 58336 KiB
1_07.txt AC 871 ms 58120 KiB
1_08.txt AC 862 ms 58616 KiB
1_09.txt AC 821 ms 58360 KiB
1_10.txt AC 882 ms 58356 KiB
1_11.txt AC 799 ms 58216 KiB
1_12.txt AC 807 ms 58224 KiB
1_13.txt AC 831 ms 58044 KiB
1_14.txt AC 823 ms 58400 KiB
1_15.txt AC 843 ms 58584 KiB
1_16.txt AC 824 ms 58468 KiB
1_17.txt AC 847 ms 58412 KiB
1_18.txt AC 843 ms 58220 KiB
1_19.txt AC 878 ms 58040 KiB
1_20.txt AC 785 ms 58212 KiB
1_21.txt AC 866 ms 58276 KiB
1_22.txt AC 819 ms 58152 KiB
1_23.txt AC 829 ms 58296 KiB