Submission #1406415


Source Code Expand

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main (String[] args) throws java.lang.Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        char[] ca = in.next().toCharArray();
        int k = in.nextInt();
        for (int i = 0; i < ca.length; i++) {
            if (ca[i] != 'a' && (('z' + 1 - ca[i]) <= k)) {

                k -= 'z' + 1 - ca[i];
                ca[i] = 'a';

            }
            if (k < 0)
                break;
        }
        if (k > 0) {
            k %= 26;
            int temp = (ca[ca.length - 1] + k) % 123;
            if (temp < 97) {
                //System.out.println("temp is : " + temp);
                char z = 'a';
                z += temp;
                ca[ca.length - 1] = z;
            } else {
                //System.out.println("hi");
                ca[ca.length - 1] = (char)temp;
            }
        }
        w.println(new String(ca));
        w.close();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1)
                return -1;
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0)
                read();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }
        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1)
                read();
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

Submission Info

Submission Time
Task C - Next Letter
User ashubeckham
Language Java8 (OpenJDK 1.8.0)
Score 400
Code Size 5265 Byte
Status AC
Exec Time 107 ms
Memory 21972 KB

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 74 ms 21076 KB
0_01.txt AC 69 ms 18772 KB
0_02.txt AC 69 ms 20948 KB
1_00.txt AC 79 ms 19152 KB
1_01.txt AC 67 ms 19284 KB
1_02.txt AC 68 ms 19156 KB
1_03.txt AC 70 ms 21204 KB
1_04.txt AC 66 ms 19284 KB
1_05.txt AC 69 ms 19156 KB
1_06.txt AC 101 ms 19796 KB
1_07.txt AC 99 ms 20052 KB
1_08.txt AC 88 ms 20308 KB
1_09.txt AC 99 ms 21716 KB
1_10.txt AC 106 ms 18644 KB
1_11.txt AC 97 ms 20052 KB
1_12.txt AC 97 ms 18900 KB
1_13.txt AC 98 ms 21076 KB
1_14.txt AC 98 ms 20180 KB
1_15.txt AC 97 ms 21076 KB
1_16.txt AC 99 ms 19796 KB
1_17.txt AC 107 ms 19924 KB
1_18.txt AC 100 ms 21972 KB
1_19.txt AC 105 ms 20180 KB
1_20.txt AC 99 ms 20052 KB
1_21.txt AC 101 ms 19028 KB
1_22.txt AC 105 ms 19668 KB
1_23.txt AC 98 ms 18516 KB