码迷,mamicode.com
首页 > 其他好文 > 详细

题解:CERC2015 ASCII Addition

时间:2018-10-20 19:50:14      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:实现   letter   现在   back   行高   positive   sts   HERE   bad   

庆祝通过noip2018初赛,系列五题EP5.

题目描述:

题意翻译

题目背景

现在,如果你只是用手机的相机对着它们,智能手机应用可以即时翻译文本,甚至解决数学问题。您的工作是实现一个更简单的功能,回忆过去——添加两个作为ASCII艺术的整数。

题目描述

ASCII艺术是一个字符矩阵,正好是7行高,每个字符都是点或小写字母X。

给出了A +B形式的表达式,其中A和B都是正整数。通过将所有的表达式字符(A和B的数字以及符号)作为7 5个矩阵,将这些矩阵转换成ASCII艺术,并将矩阵与单个字符的单个列串联在连续的各个矩阵之间。对应于数字和+符号的精确矩阵如下:

技术分享图片

给定一个ASCII艺术来表达A+B的形式,找到加法的结果并用ASCII艺术形式写出。

输入输出格式

输入格式:

输入由7行组成,包含用于A+B形式的表达式的ASCII技术,其中A和B都是由至多9个十进制数字组成的正整数,并且没有前导零。

输出格式:

输出包含ASCII艺术的7行,对应于加法的结果,没有前导零。

感谢@剑圣夜雨声烦 提供的翻译

题目背景

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 follows:

技术分享图片

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 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 7 lines containing ASCII art corresponding to the result of the addition, without leading zeros.

 

输入输出样例

输入样例#1: 复制
....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
输出样例#1: 复制
....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

说明

样例:1234567+890=1235457

Central Europe Regional Contest 2015 Problem A

解题思路:

大致是一道模拟题

(庆祝通过noip2018提高组初赛第五题)(五道黑题时代结束,之后开始正常练习)

下面上代码:

 

 1#include<bits/stdc++.h>
2#define int long long 
3using namespace std;
4map<string,int> m;
5string st; 
6string s[7];
7int n,row,line,loc,a,b,res,ans,w,ret;
8char out[10][5000];
9bool skip;
10void Init(){
11    st="xxxxxx...xx...xx...xx...xx...xxxxxx";
12    m.insert(pair<string,int>(st,0));
13    st="....x....x....x....x....x....x....x";
14    m.insert(pair<string,int>(st,1));
15    st="xxxxx....x....xxxxxxx....x....xxxxx";
16    m.insert(pair<string,int>(st,2));
17    st="xxxxx....x....xxxxxx....x....xxxxxx";
18    m.insert(pair<string,int>(st,3));
19    st="x...xx...xx...xxxxxx....x....x....x";
20    m.insert(pair<string,int>(st,4));
21    st="xxxxxx....x....xxxxx....x....xxxxxx";
22    m.insert(pair<string,int>(st,5));
23    st="xxxxxx....x....xxxxxx...xx...xxxxxx";
24    m.insert(pair<string,int>(st,6));
25    st="xxxxx....x....x....x....x....x....x";
26    m.insert(pair<string,int>(st,7));
27    st="xxxxxx...xx...xxxxxxx...xx...xxxxxx";
28    m.insert(pair<string,int>(st,8));
29    st="xxxxxx...xx...xxxxxx....x....xxxxxx";
30    m.insert(pair<string,int>(st,9));
31}
32void solve(){
33    for (int i=0;i<7;i++)
34        cin>>s[i];
35    n=s[0].length();
36    n=n/6; skip=true;n++;
37    for (int i=1;i<=n;i++){
38        loc=(i-1)*6;
39        st="";
40        for (int j=0;j<35;j++){
41            row=j/5; line=j%5;
42            st=st+s[row][loc+line];            
43        }
44        if (skip){
45            if (!m.count(st)){
46                skip=false;
47                continue;
48            } 
49            res=m[st];
50            a=a*10+res;
51        } else {
52            res=m[st];
53            b=b*10+res;
54        }
55    }
56    ans=a+b;
57}
58void writeln(string t,int num){
59    loc=(num-1)*5;
60    for (int i=0;i<35;i++){
61        row=i/5;line=i%5;
62        out[row][line+loc]=t[i];
63    } 
64}
65void write(int num){
66    res=1;w=0;
67    while (res<=num){
68        w++;res*=10;
69    }
70    for (int i=1;i<=w;i++){
71        res/=10;
72        ret=num/res;ret%=10;
73        std::map<string,int>::iterator it;
74        for (it=m.begin();it!=m.end();it++)
75            if (it->second==ret)
76                writeln(it->first,i); 
77    }
78    for (int i=0;i<7;i++){
79        for (int j=0;j<(w*5);j++){
80            cout << out[i][j];
81            if (j%5==4&&j!=w*5-1)
82                cout << ".";
83        }
84        cout << endl;
85    }
86}
87main(){
88    Init();
89    solve();
90    write(ans);
91    return 0;
92

题解:CERC2015 ASCII Addition

标签:实现   letter   现在   back   行高   positive   sts   HERE   bad   

原文地址:https://www.cnblogs.com/titititing/p/9822574.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!