Submission #891689


Source Code Expand

import static java.lang.Math.*;
import static java.util.Arrays.*;
 
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
import static java.math.BigInteger.*;
 
public class Main {
	
	void solve() {
		char[] s = sc.next().toCharArray();
		int n = s.length;
		int K = sc.nextInt();
		
		for (int i = 0; i < n; i++) {
			int need = 1 + 'z' - s[i];
			if (need <= K) {
				s[i] = 'a';
				K -= need;
			}
		}
		if (K > 0) { K %= 26; }
		while (K-->0) {
			if (s[n-1] == 'z') s[n-1] = 'a'; else s[n-1]++;
		}
		out.println(new String(s));
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }
 
	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}
 
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
 
	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}
 
	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;
 
		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Submission Info

Submission Time
Task C - Next Letter
User hs484
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 2427 Byte
Status WA
Exec Time 204 ms
Memory 11476 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 19
WA × 8
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 96 ms 8144 KB
0_01.txt AC 96 ms 8144 KB
0_02.txt AC 96 ms 8144 KB
1_00.txt AC 94 ms 8272 KB
1_01.txt AC 97 ms 8148 KB
1_02.txt AC 96 ms 8144 KB
1_03.txt AC 95 ms 8148 KB
1_04.txt AC 96 ms 8144 KB
1_05.txt AC 96 ms 8144 KB
1_06.txt AC 128 ms 11476 KB
1_07.txt AC 131 ms 11472 KB
1_08.txt WA 128 ms 11348 KB
1_09.txt WA 128 ms 11220 KB
1_10.txt WA 127 ms 11344 KB
1_11.txt WA 126 ms 11348 KB
1_12.txt WA 125 ms 11344 KB
1_13.txt WA 126 ms 11348 KB
1_14.txt WA 128 ms 11348 KB
1_15.txt WA 129 ms 11348 KB
1_16.txt AC 130 ms 11344 KB
1_17.txt AC 130 ms 11344 KB
1_18.txt AC 204 ms 11344 KB
1_19.txt AC 127 ms 11476 KB
1_20.txt AC 129 ms 11216 KB
1_21.txt AC 130 ms 11344 KB
1_22.txt AC 130 ms 11400 KB
1_23.txt AC 130 ms 11344 KB