沐里纷纷


私信TA

用户名:Epoch

访问量:63045

签 名:

我不会算法

等  级
排  名 37
经  验 12836
参赛次数 1
文章发表 172
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

不会算法

解题思路:
瞎写的,不知道为什么错......


注意事项:

参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区