前言
不要被题目的难度标签所迷惑 ——鲁迅
思路(解题方式)
- 将字符串读入并处理成整型
- 将答案用规定方式输出
思路非常清晰的一道题,只是一个轻量级模拟而已(什么?不算轻量级?去看看琪露诺的冰雪小屋和猪国杀就知道这题是多么轻量级的一个模拟了)
小技巧
代码本身难度不大,可以运用一些小技巧来减少码量及思维难度
- 用数组存下每一个数字的表示方式,方便比对
- 可以将代码多分成几个函数来实现,方便查错及梳理思路
然后就是代码了
应该不需要太多注释吧,思路已经很清楚了
#include<iostream>
#include<cstring>
using namespace std;
#define For(i,l,r) for(int i=l;i<r;i++)//减少码量
string a[7];//存算式
int ans[30];//演算出的结果按位存在此数组里
long long add1=0,add2=0;//两个加数
string n[11][7]={"xxxxx","x...x","x...x","x...x","x...x","x...x","xxxxx",
"....x","....x","....x","....x","....x","....x","....x",
"xxxxx","....x","....x","xxxxx","x....","x....","xxxxx",
"xxxxx","....x","....x","xxxxx","....x","....x","xxxxx",
"x...x","x...x","x...x","xxxxx","....x","....x","....x",
"xxxxx","x....","x....","xxxxx","....x","....x","xxxxx",
"xxxxx","x....","x....","xxxxx","x...x","x...x","xxxxx",
"xxxxx","....x","....x","....x","....x","....x","....x",
"xxxxx","x...x","x...x","xxxxx","x...x","x...x","xxxxx",
"xxxxx","x...x","x...x","xxxxx","....x","....x","xxxxx",
".....","..x..","..x..","xxxxx","..x..","..x..","....."};//每一个数字的表示方式
bool equ(int x,int u){
For(i,0,7)
For(j,x,x+5)
if(n[u][i][j-x]!=a[i][j])
return false;
return true;
}//判断一个位置上的数字是否为u(u为10是代表加号)
int wt(int x){
For(i,0,11)
if(equ(x,i))
return i;
}//判断一个位置上的数字(或加号)是什么
void print(int cnt){
For(loop,0,7){
for(int i=cnt-1;i>=0;i--){
For(j,0,5)cout<<n[ans[i]][loop][j];
if(i)cout<<'.';
}cout<<endl;
}
}//输出答案
int main()
{
For(i,0,7)cin>>a[i];
int t;
long long x;
bool flag=true;
for(int i=0;i<a[0].size();i+=6){
t=wt(i);
if(t!=10&&flag)
add1*=10,add1+=t;
else if(t==10)
flag=false;
else
add2*=10,add2+=t;
}//识别出两个加数
int cnt=0;
x=add1+add2;
while(x!=0){
ans[cnt++]=x%10;
x/=10;
}//将答案按位分进ans数组中
print(cnt);
return 0;
}
代码只有62行,应该不算长吧~