【枚举】URAL - 2081 - Faulty dial

本文介绍了一个使用C++实现的字符识别程序,该程序通过对比预设的字符模板来识别输入的字符图案,并输出对应的数字组合。文章详细展示了程序如何读取字符图案、对比模板以及确定最佳匹配的过程。
//._. ... ._. ._. ... ._. ._. ._. ._. ._.
//|.| ..| ._| ._| |_| |_. |_. ..| |_| |_|
//|_| ..| |_. ._| ..| ._| |_| ..| |_| ._|
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef pair<int,int> Point;
char table[10][3][4]={
{
	"._.",
	"|.|",
	"|_|"
},
{
	"...",
	"..|",
	"..|"
},
{
	"._.",
	"._|",
	"|_."
},
{
	"._.",
	"._|",
	"._|"
},
{
	"...",
	"|_|",
	"..|"
},
{
	"._.",
	"|_.",
	"._|"
},
{
	"._.",
	"|_.",
	"|_|"
},
{
	"._.",
	"..|",
	"..|"
},
{
	"._.",
	"|_|",
	"|_|"
},
{
	"._.",
	"|_|",
	"._|"
}
};
char b[3][30];
bool cant[5][10];
int l[5],r[5],n;
int main()
{
	//freopen("d.in","r",stdin);
	l[1]=0; r[1]=2;
	l[2]=4; r[2]=6;
	l[3]=10; r[3]=12;
	l[4]=14; r[4]=16;
	scanf("%d",&n);
	Point Pre;
	for(int i=1;i<=n;++i)
	  {
	  	memset(cant,0,sizeof(cant));
	  	for(int j=0;j<3;++j)
	  	  scanf("%s",b[j]);
	  	for(int j=1;j<=4;++j)
	  	  {
	  	  	for(int p=0;p<10;++p){
	  	  	for(int k=0;k<3;++k)
	  	  	  for(int l1=0,l2=l[j];l1<3;++l1,++l2)
	  	  	    if(table[p][k][l1]=='.' && b[k][l2]!='.')
	  	  	      {
	  	  	      	cant[j][p]=1;
	  	  	      	goto OUT;
	  	  	      }
	  	  	      OUT:;
	  	  	  }
	  	  }
	  	for(int j=9;j>=0;--j)
	  	for(int k=9;k>=0;--k)
	  	for(int l=9;l>=0;--l)
	  	for(int p=9;p>=0;--p)
	  	  if((!cant[1][j]) && (!cant[2][k]) && (!cant[3][l]) && (!cant[4][p]) && (j<6 && l<6))
	  	    if(i==1 || Point(j*10+k,l*10+p)<Pre)
	  	      {
	  	      	printf("%d%d:%d%d\n",j,k,l,p);
	  	      	Pre=Point(j*10+k,l*10+p);
	  	      	goto OU2;
	  	      }
	  	OU2:;
	  }
	return 0; 
}          

转载于:https://www.cnblogs.com/autsky-jadek/p/6375221.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值