--- 这里是 cjiaw 的小窝(●'◡'●) ---

正在玩命加载中......

洛谷__P4346 [CERC2015] ASCII Addition

题目背景

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

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

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

16222

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

输入格式

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

输出格式

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

输入输出样例

输入 #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

代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<tuple>
#define inf 72340172838076673
#define int long long
#define endl '\n'
#define F first
#define S second
#define  mst(a,x) memset(a,x,sizeof (a))
using namespace std;
typedef pair<int, int> pii;

const int N = 20, mod = 998244353;

int n = 7;
string s[N], sum[N];
int pos = 0;

string e[N] = {
    "xxxxx.x...x.x...x.x...x.x...x.x...x.xxxxx.",//0
    "....x.....x.....x.....x.....x.....x.....x.",//1
    "xxxxx.....x.....x.xxxxx.x.....x.....xxxxx.",//2
    "xxxxx.....x.....x.xxxxx.....x.....x.xxxxx.",//3
    "x...x.x...x.x...x.xxxxx.....x.....x.....x.",//4
    "xxxxx.x.....x.....xxxxx.....x.....x.xxxxx.",//5
    "xxxxx.x.....x.....xxxxx.x...x.x...x.xxxxx.",//6
    "xxxxx.....x.....x.....x.....x.....x.....x.",//7
    "xxxxx.x...x.x...x.xxxxx.x...x.x...x.xxxxx.",//8
    "xxxxx.x...x.x...x.xxxxx.....x.....x.xxxxx.",//9
};

int r() {
    string ss ;
    for (int i = 0; i < n; i++) ss += s[i].substr(pos, 6);
    pos += 6;
    for (int i = 0; i < 10; i++) if (e[i] == ss) return i;
    return -1;
}

int read() {

    int x = r() ;
    for (int i = r(); ~i; i = r()) {
        x = x * 10 + i ;
    }
    return x;
}

void change(int res, int end) {

    if (res > 9) change(res / 10, 1);
    for (int i = 0; i < n; i++) {
        sum[i] += e[res % 10].substr(i * 6, 5 + end);
    }
}

void solve() {

    for (int i = 0; i < n; i++) {
        cin >> s[i];
        s[i] += ".";
    }
    
    int a = read(), b = read();
    int res = a + b;
    change(res, 0);  
    for (int i = 0; i < n; i++) cout << sum[i] << endl;
   
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    int T = 1;
// cin >> T;
    while (T--) solve();
    
    return 0;
}

题目链接:P4346 [CERC2015] ASCII Addition - 洛谷

 

posted @ 2025-10-06 20:28  wwjjw  阅读(13)  评论(0)    收藏  举报