Content

Board ID 928
Writer 허진경
Write Date 2018-10-26 21:35:44
Subject 단순2진암호코드
Content 그래도 시간이 절반은...
import java.io.FileInputStream;
import java.util.Scanner;

public class 단순2진암호코드 {
	public static void main(String[] args) throws Exception {
		System.setIn(new FileInputStream("단순2진암호코드_input.txt"));
		Scanner sc = new Scanner(System.in);
		
		int T;
		T=sc.nextInt();
		String[] code = new String[T];
		for(int tc=1; tc<=T; tc++) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			sc.nextLine();
			String[] card = new String[N];
			for(int i=0; i<N; i++ ) {
				card[i]=sc.nextLine();
				int start = card[i].indexOf('1');
				int end = card[i].lastIndexOf('1');
//				System.out.printf("%d %d %d\n", start, end, end-start+1);
				if(end-start > 0) {
					code[tc-1] = card[i].substring(end-55, end+1);
//					return;
//					System.out.println(code[tc-1]);
//					System.out.println(code[tc].length());
					
				}
			}
//			System.out.println(code[tc-1]);
			int[] number = new int[8];
			int index = 0;
			for(int i=0; i<code[tc-1].length(); i=i+7) {
				String numStr = code[tc-1].substring(i, i+7);
//				System.out.printf("%s ", numStr);
				int num = 0;
				switch(numStr) {
				case "0001101" : //0
					num = 0;
					break;
				case "0011001" : //1
					num = 1;
					break;
				case "0010011" : //2
					num = 2;
					break;
				case "0111101" : //3
					num = 3;
					break;
				case "0100011" : //4
					num = 4;
					break;
				case "0110001" : //5
					num = 5;
					break;
				case "0101111" : //6
					num = 6;
					break;
				case "0111011" : //7
					num = 7;
					break;
				case "0110111" : //8
					num = 8;
					break;
				case "0001011" : //9
					num = 9;
					break;
				}
				number[index++] = num;
			}
//			System.out.println();
			
			int checksum = 0;
			int sum = 0;
			for(int i=0; i<number.length; i++) {
				if(i % 2 == 0) {
					checksum += (number[i] * 3);
				}else {
					checksum += number[i];
				}
				sum += number[i];
//				System.out.printf("%d ", number[i]);
			}
//			System.out.println(checksum);
			int result = 0;
			if (checksum % 10 == 0) {
				result = sum;
			}else {
				result = 0;
			}
			System.out.printf("#%d %d\n", tc, result);
					
		}
	}
}
데이터파일
2
16 80
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000011101101100010111011011000101100010001101001001101110110000000000
00000000000000011101101100010111011011000101100010001101001001101110110000000000
00000000000000011101101100010111011011000101100010001101001001101110110000000000
00000000000000011101101100010111011011000101100010001101001001101110110000000000
00000000000000011101101100010111011011000101100010001101001001101110110000000000
00000000000000011101101100010111011011000101100010001101001001101110110000000000
00000000000000011101101100010111011011000101100010001101001001101110110000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
11 70
00000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000
00000001100101000110100011010111101101110010011001001101110110000000000
00000001100101000110100011010111101101110010011001001101110110000000000
00000001100101000110100011010111101101110010011001001101110110000000000
00000001100101000110100011010111101101110010011001001101110110000000000
00000001100101000110100011010111101101110010011001001101110110000000000
00000001100101000110100011010111101101110010011001001101110110000000000
00000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000