94 计算器

94 计算器

作者: Turbo时间限制: 1S章节: 宽度优先搜索

问题描述 :

  王小二的计算器上面的LED显示屏坏掉了,于是他找到了在计算器维修与应用系学习的你来为他修计算器。
  屏幕上可以显示0~9的数字,其中每个数字由7个小二极管组成,各个数字对应的表示方式如图所示:

  
  为了排除电路故障,现在你需要计算,将数字A变为数字B需要经过多少次变换?
  注意:现在将其中每段小二极管的开和关都定义为一次变换。例如数字1变为2是5次操作。

【样例输入1】
  3
  101
  025
【样例输出1】
  12

【样例输入2】
  8
  19920513
  20111211
【样例输出2】
  27

输入说明 :

  第一行为一个正整数L,表示数码的长度。
  接下来两行是两个长度为L的数字A和B,表示要把数字A变成数字B(数字可以以0开头)。

  L<=100

输出说明 :

  一行一个整数,表示这些小二极管一共要变换多少次。

输入范例 :
8
91305830
22653549

输出范例 :
23

#include <iostream>
#include <string>
using namespace std;
string str[10] = { "0111111", "0000110", "1011011", "1001111", "1100110", "1101101", "1111101", "0000111", "1111111", "1101111" };
int main()
{
	int n;
	cin >> n;
	string res1, res2;
	cin >> res1 >> res2;
	int n1[201], n2[201];
	for (int i = 0; i < n; i++)
	{
		n1[i] = res1[i] - '0';
		n2[i] = res2[i] - '0';
	}
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		string str1, str2;
		str1 = str[n1[i]];
		str2 = str[n2[i]];
		for (int j = 0; j < 7; j++)
		{
			if ((str1[j]-'0') ^ (str2[j]-'0')) sum++;
		}
	}
	cout << sum << endl;
	return 0;
}
Yesterday is history,tomorrow ismystery,but today is a gift!That why it is called Present!
原文地址:https://www.cnblogs.com/VictorierJwr/p/12878539.html