結果

問題 No.432 占い(Easy)
ユーザー uwi
提出日時 2016-10-14 22:24:25
言語 Java8
(openjdk 1.8.0.191)
結果
AC  
実行時間 112 ms
コード長 3,396 Byte
コンパイル時間 2,764 ms
使用メモリ 21,496 KB
最終ジャッジ日時 2019-03-31 19:59:08

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0_sample_1.in AC 86 ms
19,184 KB
0_sample_2.in AC 86 ms
19,184 KB
0_sample_3.in AC 85 ms
19,184 KB
0_sample_4.in AC 89 ms
19,172 KB
1_easy_small_1.in AC 86 ms
19,212 KB
1_easy_small_2.in AC 87 ms
19,192 KB
1_easy_small_3.in AC 86 ms
19,208 KB
1_easy_small_4.in AC 86 ms
19,208 KB
1_easy_small_5.in AC 85 ms
19,192 KB
2_easy_large_1.in AC 93 ms
19,548 KB
2_easy_large_2.in AC 88 ms
19,368 KB
2_easy_large_3.in AC 89 ms
19,540 KB
2_easy_large_4.in AC 112 ms
21,496 KB
2_easy_large_5.in AC 111 ms
21,476 KB
2_easy_large_6.in AC 91 ms
19,540 KB
7_special_0.in AC 87 ms
19,192 KB
7_special_1.in AC 85 ms
19,188 KB
7_special_2.in AC 111 ms
21,468 KB
8_easy_rand_1.in AC 99 ms
20,472 KB
8_easy_rand_2.in AC 97 ms
19,972 KB
8_easy_rand_3.in AC 91 ms
19,612 KB
8_easy_rand_4.in AC 91 ms
19,672 KB
8_easy_rand_5.in AC 90 ms
19,384 KB
8_easy_rand_6.in AC 93 ms
19,500 KB
8_easy_rand_7.in AC 94 ms
19,536 KB
8_easy_rand_8.in AC 93 ms
19,544 KB
テストケース一括ダウンロード

ソースコード

diff #
package contest161014;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class B {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		for(int T = ni();T > 0;T--){
			char[] s = ns().toCharArray();
			int[] a = new int[s.length];
			for(int i = 0;i < s.length;i++){
				a[i] = s[i]-'0';
			}
			int n = s.length;
			for(int i = 0;i < n-1;i++){
				int[] b = new int[n-1-i];
				for(int j = 0;j < b.length;j++){
					b[j] = a[j]+a[j+1];
					b[j] = b[j]/10+b[j]%10;
				}
				a = b;
			}
			out.println(a[0]);
		}
	}
	
	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
//		Thread t = new Thread(null, null, "~", Runtime.getRuntime().maxMemory()){
//			@Override
//			public void run() {
//				long s = System.currentTimeMillis();
//				solve();
//				out.flush();
//				if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
//			}
//		};
//		t.start();
//		t.join();
	}
	
	public static void main(String[] args) throws Exception { new B().run(); }
	
	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private long[] nal(int n)
	{
		long[] a = new long[n];
		for(int i = 0;i < n;i++)a[i] = nl();
		return a;
	}
	
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[][] nmi(int n, int m) {
		int[][] map = new int[n][];
		for(int i = 0;i < n;i++)map[i] = na(m);
		return map;
	}
	
	private int ni() { return (int)nl(); }
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}
0