Java implementation of the Blue Bridge Cup VIP improving algorithm calculator

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

Algorithm improves calculator
Time limit: 1.0s Memory Limit: 256.0MB
[Problem Description]
  calculator above Wangxiao LED display is broken, so he found a calculator application system maintenance and learning you for coming to him repair calculator.
  Numbers 0 to 9 can be displayed on the screen, wherein each of the small number of diodes 7, as shown in the respective digital representation corresponding to FIG:

Here Insert Picture Description

In order to exclude circuit fault, and now you need to calculate the numbers A to B the number of times the digital transformation need to go through?
  Note: wherein each segment will now small diode on and off is defined as the primary conversion. Such as digital 1 to 2 five operations.

[Input format
  of the first acts a positive integer L, represents the length of the digital.
  The next two lines of length L is two numbers A and B, A represents put into digital numbers B (numbers may start with 0).
[Format] output
  line an integer representing the total of these small diodes to transform how many times.
Sample input [1]

. 3
  101
  025
[1] Sample Output
  12
[2] Sample Input

. 8
  19,920,513
  20,111,211
[2] Sample Output
  27

Data range []
  L <= 100

import java.util.Scanner;


public class 计算器 {
	public static void main(String[] args) {
		Scanner out=new Scanner(System.in);
		int L=out.nextInt();
		String a=out.next();
		String b=out.next();
		int[][] arr={
				{1,1,1,1,1,1,0},
				{0,1,1,0,0,0,0},
				{1,1,0,1,1,0,1},
				{1,1,1,1,0,0,1},
				{0,1,1,0,0,1,1},
				{1,0,1,1,0,1,1},
				{1,0,1,1,1,1,1},
				{1,1,1,0,0,0,0},
				{1,1,1,1,1,1,1},
				{1,1,1,1,0,1,1}
		};
		char[] c1=a.toCharArray();
		char[] c2=b.toCharArray();
		int count=0;
		for (int i = 0; i < L; i++) {
			for (int j = 0; j < 7; j++) {
				if(arr[c1[i]-'0'][j]!=arr[c2[i]-'0'][j]) count++;
			}
		}
		System.out.println(count);
	}

}

Guess you like

Origin blog.csdn.net/a1439775520/article/details/93300099