我正在尝试使用TTMath在C ++中编写Tuppers Formula来存储大整数。但我的输出只是乱七八糟的混乱,而不是它应该显示的图片。我无法解决造成这种情况的原因。
#include <iostream>
#include <fstream>
#include <ttmath/ttmath.h>
int main(int argsm, int** args)
{
const ttmath::Int<1> HEIGHT = 17;
const ttmath::Int<1> WIDTH = 106;
ttmath::Big<300, 300> a, b, c, d, e, f, g, h, i, j, k, l, y;
std::ofstream newFile;
char matrix[107][18];
newFile.open("image.txt");
for (ttmath::UInt<3> x = 0; x < WIDTH; ++x)
{
y = ttmath::Big<1, 200>("9609393799189588849716729621278527547150043396601293066515055192717028023952664246896428421743507 18121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404719");
for (ttmath::UInt<2> v = 0; v <= HEIGHT; ++v)
{
k = y;
a = y;
a.Mod(17);
b = a;
c = x;
c.Mul(17);
b.Mul(1);
d = c + b;
d.Pow(2);
e = d;
k.Div(17);
f = k ;
g = f;
g.Div(e);
h = g;
h.Mod(2);
j = h;
j > 0.5 ? matrix[stoi(x.ToString())][stoi(v.ToString())] = '\u2588' : matrix[stoi(x.ToString())][stoi(v.ToString())] = ' ';
y.Add(1);
}
}
for (signed int h = 0; h < std::stoi(HEIGHT.ToString()); ++h)
{
for (signed int w = 0; w < std::stoi(WIDTH.ToString()); ++w)
{
newFile << matrix[w][h];
}
newFile << "\n";
}
newFile.close();
return 0;
}
答案 0 :(得分:0)
除了评论中指出的其他一些问题外,主要问题似乎是该行
d.Pow(2);
计算d^2
,当你想要的是2^d
。
关于评论中的第二个问题:为了将生成的图像翻转过来,您只需使用
newFile << matrix[w][HEIGHT-h-1];
输出行。