Submission #347281


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	
	public void run() {
		String s = in.next();
		
		int n = s.length();
		int cnt = 1;
		char c = s.charAt(0);
		String res = "";
		for (int i = 1; i < n; i++) {
			char nc = s.charAt(i);
			if (c != nc) {
				res += c;
				res += cnt;
				cnt = 1;
				c = nc;
			} else {
				cnt++;
			}
		}
		res += c;
		res += cnt;
		System.out.println(res);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

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

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

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

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

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

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

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

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

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Submission Info

Submission Time
Task B - 高橋くんと文字列圧縮
User hiro116s
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 3803 Byte
Status AC
Exec Time 433 ms
Memory 28164 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 33
Set Name Test Cases
Sample subtask0_1.txt, subtask0_2.txt, subtask0_3.txt
All 0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt
Case Name Status Exec Time Memory
0.txt AC 406 ms 28140 KB
1.txt AC 404 ms 28152 KB
10.txt AC 378 ms 20792 KB
11.txt AC 376 ms 20904 KB
12.txt AC 387 ms 20904 KB
13.txt AC 401 ms 20812 KB
14.txt AC 379 ms 20764 KB
15.txt AC 381 ms 20928 KB
16.txt AC 379 ms 20808 KB
17.txt AC 379 ms 20856 KB
18.txt AC 379 ms 20756 KB
19.txt AC 382 ms 20788 KB
2.txt AC 406 ms 28080 KB
20.txt AC 380 ms 20752 KB
21.txt AC 380 ms 20612 KB
22.txt AC 380 ms 20652 KB
23.txt AC 380 ms 20652 KB
24.txt AC 381 ms 20620 KB
25.txt AC 374 ms 20652 KB
26.txt AC 388 ms 20664 KB
27.txt AC 387 ms 20588 KB
28.txt AC 389 ms 20744 KB
29.txt AC 391 ms 20736 KB
3.txt AC 416 ms 28096 KB
4.txt AC 412 ms 28064 KB
5.txt AC 410 ms 28152 KB
6.txt AC 433 ms 28164 KB
7.txt AC 420 ms 28008 KB
8.txt AC 421 ms 28016 KB
9.txt AC 414 ms 28140 KB
subtask0_1.txt AC 380 ms 20732 KB
subtask0_2.txt AC 375 ms 20632 KB
subtask0_3.txt AC 376 ms 20688 KB