UVA 10415 Java

import java.util.*;
import static java.lang.System.*;

public class main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
  	int cases = sc.nextInt();
  	for(int t = 0; t < cases; t++)
  	{
  		String finger[] = {"c0111001111", "d0111001110", "e0111001100", "f0111001000", "g0111000000", "a0110000000", "b0100000000",
  		"C0010000000", "D1111001110", "E1111001100", "F1111001000", "G1111000000", "A1110000000", "B1100000000"};
  		String current = "00000000000";
  		String cmd = sc.next();
  		int[] count = new int[10];
  		for(int index = 0; index < cmd.length(); index++)
  		{
  			char c = cmd.charAt(index);
  			for(int i = 0; i < 14; i++)
  			{
  				if(finger[i].charAt(0) == c)
  				{
  					String temp = finger[i];
  					for(int j = 1; j < 11; j++)
  					{
  						if(current.charAt(j) == '0' && temp.charAt(j) == '1')
  						{
  							count[j-1]++;
  						}
  					}
  					current = temp;
  					break;
  				}
  			}
  		}
  		for(int i = 0; i < 10; i++)
  		{
  			System.out.print(count[i]);
  			if(i != 9)
  				System.out.print(" ");
  		}
  		System.out.println();
  	}
  }
};

留言

這個網誌中的熱門文章

C# 井字遊戲