原题链接:蓝桥杯算法提高VIP-乘法运算
解题思路:
瞎写的,不知道为什么错......
注意事项:
参考代码:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
char A[7][4];
void solve(int a, int b)
{
int res = a * b;
A[0][3] = a % 10 + '0';
A[0][2] = (a / 10 == 0 && (int)log(a) + 1 < 2 ? ' ' : a / 10 + '0');
A[1][0] = '*';
A[1][1] = (b / 10 == 0 && (int)log(b) + 1 < 2 ? ' ' : b / 10 + '0');
A[1][2] = b % 10 + '0';
A[2][0] = A[2][1] = A[2][2] = '-';
int temp1 = (b % 10)*a, temp2 = (b / 10)*a;
A[3][3] = temp1 % 10 + '0';
A[3][2] = (temp1 / 10 % 10 == 0 && (int)log(temp1) + 1 < 2 ? ' ' : temp1 / 10 % 10 + '0');
A[3][1] = (temp1 / 100 == 0 && (int)log(temp1) + 1 < 3 ? ' ' : temp1 / 100 + '0');
if (temp2 == 0) return;
A[4][2] = temp2 % 10 + '0';
A[4][1] = (temp2 / 10 % 10 == 0 && (int)log(temp2) + 1 < 2 ? ' ' : temp2 / 10 % 10 + '0');
A[4][0] = (temp2 / 100 == 0 && (int)log(temp2) + 1 < 3 ? ' ' : temp2 / 100 + '0');
A[5][0] = A[5][1] = A[5][2] = '-';
A[6][3] = res % 10 + '0';
A[6][2] = (res / 10 % 10 == 0 && (int)log(res) + 1 < 2 ? ' ' : res / 10 % 10 + '0');
A[6][1] = (res / 100 == 0 && (int)log(res) + 1 < 3 ? ' ' : res / 100 % 10 + '0');
A[6][0] = (res / 1000 == 0 && (int)log(res) + 1 < 4 ? ' ' : res / 1000 + '0');
}
void clearA()
{
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 4; j++)
{
if (A[i][j] == '\0' || A[i][j] == ' ')
continue;
else if (A[i][j] == '0')
{
A[i][j] = '\0';
break;
}
else if (A[i][j] >= '1' && A[i][j] <= '9')
break;
}
}
if (A[3][0] == '\0' && A[3][1] == ' ' && A[3][2] == ' ' && A[3][3] == '\0')
A[3][2] = A[3][3] = '0';
if (A[4][0] == '\0' && A[4][1] == ' ' && A[4][2] == ' ' && A[4][3] == '\0')
A[4][2] = A[4][3] = '0';
}
int main(int argc, char** argv)
{
int a, b;
cin >> a >> b;
solve(a, b);
clearA();
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 4; j++)
{
if (A[i][j] == '*')
cout << "×";
else if (A[i][j] == '-')
{
cout << "━━━";
break;
}
else
cout << A[i][j];
}
cout << endl;
}
return 0;
}0.0分
0 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复