UVALive 7324 ASCII Addition

Nowadays, there are smartphone applications that instantly translate text and even solve math problems
if you just point your phone’s camera at them. Your job is to implement a much simpler functionality
reminiscent of the past — add two integers written down as ASCII art.
An ASCII art is a matrix of characters, exactly 7 rows high, with each individual character either
a dot (.) or the lowercase letter ‘x’.
An expression of the form a+b is given, where both a and b are positive integers. The expression is
converted into ASCII art by writing all the expression characters (the digits of a and b as well as the ‘+’
sign) as 7 × 5 matrices, and concatenating the matrices together with a single column of dot characters
between consecutive individual matrices. The exact matrices corresponding to the digits and the ‘+’
sign are as folows:
xxxxx ....x xxxxx xxxxx x...x xxxxx xxxxx xxxxx xxxxx xxxxx .....
x...x ....x ....x ....x x...x x.... x.... ....x x...x x...x ..x..
x...x ....x ....x ....x x...x x.... x.... ....x x...x x...x ..x..
x...x ....x xxxxx xxxxx xxxxx xxxxx xxxxx ....x xxxxx xxxxx xxxxx
x...x ....x x.... ....x ....x ....x x...x ....x x...x ....x ..x..
x...x ....x x.... ....x ....x ....x x...x ....x x...x ....x ..x..
xxxxx ....x xxxxx xxxxx ....x xxxxx xxxxx ....x xxxxx xxxxx .....
Given an ASCII art for an expression of the form a + b, find the result of the addition and write it
out in the ASCII art form.
Input
The input file contains several test cases, each of them as described below.
Input consists of exactly 7 lines and contains the ASCII art for an expression of the form a + b,
where both a and b are positive integers consisting of at most 9 decimal digits and written without
leading zeros.
Output
For each test case, output 7 lines containing ASCII art corresponding to the result of the addition,
without leading zeros.
Sample Input
....x.xxxxx.xxxxx.x...x.xxxxx.xxxxx.xxxxx.......xxxxx.xxxxx.xxxxx
....x.....x.....x.x...x.x.....x.........x...x...x...x.x...x.x...x
....x.....x.....x.x...x.x.....x.........x...x...x...x.x...x.x...x
....x.xxxxx.xxxxx.xxxxx.xxxxx.xxxxx.....x.xxxxx.xxxxx.xxxxx.x...x
....x.x.........x.....x.....x.x...x.....x...x...x...x.....x.x...x
....x.x.........x.....x.....x.x...x.....x...x...x...x.....x.x...x
....x.xxxxx.xxxxx.....x.xxxxx.xxxxx.....x.......xxxxx.xxxxx.xxxxx
Sample Output
....x.xxxxx.xxxxx.xxxxx.x...x.xxxxx.xxxxx
....x.....x.....x.x.....x...x.x.........x
....x.....x.....x.x.....x...x.x.........x
....x.xxxxx.xxxxx.xxxxx.xxxxx.xxxxx.....x
....x.x.........x.....x.....x.....x.....x
....x.x.........x.....x.....x.....x.....x

....x.xxxxx.xxxxx.xxxxx.....x.xxxxx.....x

打个表

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
#define F(x,a,b) for(int x=a;x<=b;x++)
#define ll long long
char a[1000][1000];
struct p
{
    char num[10][10];
    int nu;
}d[12];
int rec[100];
void _c()
{
    F(i,0,12)F(j,0,9)F(k,0,9)d[i].num[j][k]='.';
    F(i,0,4){d[0].num[0][i]='x';d[0].num[6][i]='x';}F(i,0,6){d[0].num[i][0]='x';d[0].num[i][4]='x';}
    F(i,0,6){d[1].num[i][4]='x';}
    F(i,0,3){d[2].num[i][4]='x';} F(i,3,6){d[2].num[i][0]='x';}F(i,0,4){d[2].num[0][i]='x';d[2].num[3][i]='x';d[2].num[6][i]='x';}
    F(i,0,6)F(j,0,4)d[3].num[i][j]=d[2].num[i][j];F(i,4,5){d[3].num[i][0]='.';d[3].num[i][4]='x';}
    F(i,0,6)F(j,0,4)d[4].num[i][j]=d[1].num[i][j];F(i,0,3)d[4].num[i][0]='x';F(i,0,4)d[4].num[3][i]='x';
    F(i,0,6)F(j,0,4)d[5].num[i][j]=d[2].num[i][j];F(i,1,2){d[5].num[i][0]='x';d[5].num[i][4]='.';}F(i,4,5){d[5].num[i][0]='.';d[5].num[i][4]='x';}
    F(i,0,6)F(j,0,4)d[6].num[i][j]=d[5].num[i][j];F(i,4,5)d[6].num[i][0]='x';
    F(i,0,6)F(j,0,4)d[7].num[i][j]=d[1].num[i][j];F(i,0,6)d[7].num[0][i]='x';
    F(i,0,6)F(j,0,4)d[8].num[i][j]=d[6].num[i][j];F(i,1,2)d[8].num[i][4]='x';
    F(i,0,6)F(j,0,4)d[9].num[i][j]=d[8].num[i][j];F(i,4,5)d[9].num[i][0]='.';
}
int _j(int st,int en)
{
   F(k,0,9)
   {
       int flag=1;
       F(l,0,6)
       {
         F(m,0,4)
         {
             if (d[k].num[l][m]!=a[l][st+m]){flag=0;break;}
         }if (!flag) break;
       }
       if (flag) return k;
   }
   return -1;

}
int main()
{
    _c();
    while (scanf("%s",a[0])!=EOF)
    {
      F(i,1,6)scanf("%s",a[i]);
      int len=strlen(a[0]);// cout<<len<<endl;
      ll ans1=0;ll ans=0;
      for (int i=0;i<len;i+=6){int key=_j(i,i+4);if (key!=-1)ans1=ans1*10+key;else{ans=ans1;ans1=0;continue;}}
      ll t=ans+ans1;int cnt=0;
      if (t==0) {F(i,0,6){F(j,0,4)printf("%c",d[0].num[i][j]);printf("\n");}continue;}
      while (t)
      {
          rec[++cnt]=t%10;
          t/=10;
      }
      char str[1000][1000];
       F(i,0,7)F(j,0,950) str[i][j]='.';
        int stt=0;
        for (int k=cnt;k>=1;k--)
        {
            F(i,0,6)F(j,0,4)
            str[i][j+stt]=d[rec[k]].num[i][j];
            stt+=6;
        }
        F(i,0,6){F(j,0,stt-2)printf("%c",str[i][j]);printf("\n");}
    }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值