UVALive 7324 ASCII Addition (模拟)
ASCII Addition
题目链接:
http://acm.hust.edu.cn/vjudge/contest/127407#problem/A
Description
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
```
##题意:
用题所示的格式输入 A + B 的式子,要以相同格式输出结果.
##题解:
对每个数字存一下,把输入串分割成若干个数字(或'+'),然后暴力判读入的每个数即可.
注意string没有赋初值时候不能直接对某个位置赋值,直接用重定义过的'+'连接字符即可.
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 1010
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;
string num[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..",
"....."}
};
int match(string cur[]) {
for(int i=0; i<10; i++) {
int flag = 1;
for(int j=0; j<7; j++) {
for(int k=0; k<5; k++)
if(num[i][j][k] != cur[j][k]) {
flag = 0; break;
}
}
if(flag) return i;
}
return -1;
}
string data[10];
string print[10];
int main(int argc, char const *argv[])
{
//IN;
while(cin >> data[0])
{
for(int i=1; i<7; i++)
cin >> data[i];
int len = data[0].size();
int n = (len + 1) / 6;
LL a=0,b=0; int flag = 0;
int start = 0;
string cur[10];
for(int i=1; i<=n; i++) {
for(int j=0; j<7; j++) {
cur[j].clear();
for(int k=start; k<start+5; k++) {
cur[j] += data[j][k];
}
}
int dig = match(cur);
if(dig == -1) {
flag = 1;
start += 6;
continue;
}
if(!flag) {
a = a*10LL + dig;
} else {
b = b*10LL + dig;
}
start += 6;
}
LL Ans = a + b;
vector<int> ans; ans.clear();
while(Ans) {
int di = Ans % 10LL;
Ans /= 10LL;
ans.push_back(di);
}
int sz = ans.size();
for(int i=0; i<10; i++) print[i].clear();
for(int i=sz-1; i>=0; i--) {
for(int j=0; j<7; j++) {
for(int k=0; k<5; k++) {
print[j] += num[ans[i]][j][k];
}
if(i) print[j] += '.';
}
}
for(int i=0; i<7; i++) {
cout << print[i] << endl;
}
}
return 0;
}
UVALive 7324 ASCII Addition (模拟)的更多相关文章
- UVALive 7464 Robots(模拟)
7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...
- UVALive - 6269 Digital Clock 模拟
UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...
- UVALive - 7139(差分+模拟)
题目链接 参考 题意 N*M的网格,一辆车沿着网格线按给定路线走,每个网格里有一个人,人的视线始终看着车,问这些人净转圈数的平方和. 分析 由于车的起点和终点都为左上角,且每个格子里的人永远面对着车, ...
- 【Bit String Reordering UVALive - 6832 】【模拟】
题意分析 题目讲的主要是给你一个01串,然后给你要变成的01串格式,问你要转换成这一格式最少需要移动的步数. 题目不难,但当时并没有AC,3个小时的个人赛1道没AC,归根到底是没有逼自己去想,又想的太 ...
- 【Miscalculation UVALive - 6833 】【模拟】
题目分析 题目讲的是给你一个串,里面是加法.乘法混合运算(个人赛中误看成是加减乘除混合运算),有两种算法,一种是乘法优先运算,另一种是依次从左向右运算(不管它是否乘在前还是加在前). 个人赛中试着模拟 ...
- UVaLive 6809 Spokes Wheel (模拟)
题意:给定两个16进制数,问你把它转成二进制后,把第一个向左或者向右旋转最少的次数同,使得第一个变成第二个. 析:也是比较水的,按照要求做就好,注意0的情况,可能会忘记. #pragma commen ...
- [洛谷P4346][CERC2015]ASCII Addition
题目大意:给一个像素的$a+b$,每个数字为$7\times5$的像素,每两个数字之间有间隔 题解:乱搞读入 卡点:无 C++ Code: #include <cstdio> #inclu ...
- UVALive 6858 Frame (模拟)
Frame 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/D Description http://7xjob4.com1.z0 ...
- gym101480
A. ASCII Addition 模拟 #include <iostream> #include <sstream> #include <algorithm> # ...
随机推荐
- rundeck email配置文件配置
最近工作中用到了一个任务管理软件rundeck,其中有个很重要的功能就是任务执行提醒,用邮件执行,其中一些配置项,官网没有详细的说明,在网上也没有一个整体的说明,在次跟大家共享下,rundeck的使用 ...
- Git使用简介
git创建分支并直接切换到分支:git checkout -b name git提交分支到远程服务器: git push origin name/git push origin name:name ...
- DirectSound播放PCM(可播放实时采集的音频数据)
前言 该篇整理的原始来源为http://blog.csdn.net/leixiaohua1020/article/details/40540147.非常感谢该博主的无私奉献,写了不少关于不同多媒体库的 ...
- ACM - ICPC World Finals 2013 A Self-Assembly
原题下载 : http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 这道题其实是2013年我AC的第一道题,非常的开心,这 ...
- Liunx常用的特殊环境变量
[weiqiang.liu@l~]$ sh variable xiaoqiang xiaoxuenumber:2scname:variablefirst:xiaoqiangsecond:xiaoxue ...
- ti processor sdk linux am335x evm /bin/setup-package-install.sh hacking
#!/bin/sh # # ti processor sdk linux am335x evm /bin/setup-package-install.sh hacking # 说明: # 本文主要对T ...
- eclipse的使用
类似于数据库系统的三层目录结构,一般而言IDE在逻辑上都有三层目录结构:工作空间(或解决方案) -> 工程 -> 文件. 当然,如果构建java project,那么目录结构是可以更深,因 ...
- Android 长按setOnItemLongClickListener 注意细节
Java代码 gridview.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean ...
- Andorid-如何为你的Android应用缩放图片
很难为你的应用程序得到正确的图像缩放吗?是你的图片过大,造成内存问题?还是图片不正确缩放造成不良用户体验的结果?为了寻求一个好的解决方案,我们咨询了Andreas Agvard(索尼爱立信软件部门), ...
- String.valueOf()
1. 由 基本数据型态转换成 String String 类别中已经提供了将基本数据型态转换成 String 的 static 方法 也就是 String.valueOf() 这个参数多载的方法 有下 ...