Код:
#include "StdAfx.h"
#include "conio.h"
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <ctime>
#define BASE 10
#define LEN 1
const int N=51000;
using namespace std;
typedef std::vector <int> type;
void readlong (type &vec)
{
string str, str1, str2, str4;
char str3[N];
ifstream fin("in.txt");
fin.getline(str3, 2*N+2);
str2=str3;
int v;
int len1=str2.length();
for(int i=0;i<len1;i++)
if(str2[i]==' ') v=i;
char buf2[2*N+2];
memset( buf2, '\0', 2*N+2 );
str2.copy( buf2, v );
str4 = (const char*) buf2; // конвертация буфера в строку
str=str4;
//==================================================
fin.close();
int d;
int len=str.length(); // длина основной строки
for(int i=0;i<len;i++)
if(str[i]=='.') d=i;
char buf[N];
memset( buf, '\0', N );
str.copy( buf, d );
str1 = (const char*) buf; // конвертация буфера в строку
str=str1;
for (int i = str.size (); i > 0; i--)
vec.push_back (atoi (str.substr (i - LEN, LEN).c_str()));
}
void readlong1 (type &vec)
{
string str, str1, str2, str4;
char str3[N];
ifstream fin("in.txt");
fin.getline(str3, 2*N+2);
str2=str3;
int v, f, k;
int len1=str2.length();
if(str2[0]=='-') k=1; //проверка первого числа на -
//==========================
for(int i=0;i<len1;i++)
if(str2[i]==' ') {v=i; f=len1-v; }
char buf2[2*N+2];
memset( buf2, '\0', 2*N+2 );
str2.copy( buf2, v, f );
str4 = (const char*) buf2; // конвертация буфера в строку
str=str4;
//==============================
fin.close();
int len=str.length(); // длина основной строки
int d, c;
if(str[0]=='-') k=0; //проверка второго числа на -
if (k==1) {cout<<"-"; }
for(int i=0;i<len;i++)
if(str[i]=='.') d=i;
char buf[50];
memset( buf, '\0', N );
str.copy( buf, d );
str1 = (const char*) buf; // конвертация буфера в строку
str=str1;
for (int i = str.size (); i > 0; i--)
vec.push_back (atoi (str.substr (i - LEN, LEN).c_str()));
}
void readlong2 (type &vec)
{string str, str1, str2, str4;
char str3[N];
ifstream fin("in.txt");
fin.getline(str3, 2*N+2);
str2=str3;
int v;
int len1=str2.length();
for(int i=0;i<len1;i++)
if(str2[i]==' ') v=i;
char buf2[2*N+2];
memset( buf2, '\0', 2*N+2 );
str2.copy( buf2, v );
str4 = (const char*) buf2; // конвертация буфера в строку
str=str4;
//=====================
fin.close();
int len=str.length(); // длина основной строки
int d, c;
for(int i=0;i<len;i++)
if(str[i]=='.') {d=i; c=len-d;}
char buf1[N];
memset( buf1, '\0', N );
str.copy( buf1, c, d+1 );
str2 = (const char*) buf1; // конвертация буфера в строку
str=str2;
for (int i = str.size (); i > 0; i--)
vec.push_back (atoi (str.substr (i - LEN, LEN).c_str()));
}
void readlong3 (type &vec)
{ string str, str1, str2, str4;
char str3[N];
ifstream fin("in.txt");
fin.getline(str3, 2*N+2);
str2=str3;
int v, f;
int len1=str2.length();
for(int i=0;i<len1;i++)
if(str2[i]==' ') {v=i; f=len1-v; }
char buf2[2*N+2];
memset( buf2, '\0', 2*N+2 );
str2.copy( buf2, v, f );
str4 = (const char*) buf2; // конвертация буфера в строку
str=str4;
//=====================
fin.close();
int len=str.length(); // длина основной строки
int d, c;
for(int i=0;i<len;i++)
if(str[i]=='.') {d=i; c=len-d;}
char buf1[N];
memset( buf1, '\0', N );
str.copy( buf1, c, d+1 );
str2 = (const char*) buf1; // конвертация буфера в строку
str=str2;
for (int i = str.size (); i > 0; i--)
vec.push_back (atoi (str.substr (i - LEN, LEN).c_str()));
}
void mult (type &a, type &b, type &rez)
{
rez.resize (a.size() + b.size());
for (int i = 0; i < a.size(); ++i)
for (int j = 0, carry = 0; j < b.size() || carry; ++j) //сarry вес разряда
{
long long cur = rez[i+j] + a[i] * (j < b.size() ? b[j] : 0) + carry;
rez[i+j] = cur % BASE;
carry = cur / BASE;
}
while (rez.size() > 1 && rez.back() == 0)
rez.pop_back();
}