1. 结构体定义与封装
struct bigdatacom
{
private :
char dataa[];
char datab[];
public :
void init(const char *str1,const char *str2)
{
std::cout<<typeid(*this).name()<<std::endl;
strcpy(this->dataa,str1);
strcpy(this->datab,str2);
}
char * getbigdata()
{ int lengtha = strlen(dataa);
int lengthb = strlen(datab);
int *pres = (int *)malloc(sizeof(int)*(lengtha + lengthb));
memset(pres, , sizeof(int)*(lengtha + lengthb));//初始化
//累乘
for (int i = ; i < lengtha;i++)
{
for (int j = ; j < lengthb;j++)
{
pres[i+j+]+=(dataa[i] - '')*(datab[j] - '');
}
}
//进位
for (int i = lengtha + lengthb-;i>=;i--)
{
if (pres[i]>=)//进位
{
pres[i - ] += pres[i] / ;//进位
pres[i] %= ;//取出个位数
} }
int i = ;
while (pres[i]==)
{
i++;//恰好不为0的位置
}
char *lastres = (char*)malloc(sizeof(char)*(lengtha + lengthb));
int j;
for (j = ; j < lengtha + lengthb; j++, i++)
{
lastres[j] = pres[i] + '';
}
lastres[j] = '\0';
//printf("last结果=%s",lastres); return lastres; } };

2 main函数

void main()
{
bigdatacom big1; //C语言中结构体定义必须带struct,C++中不必
big1.init("","");
int n=strlen(big1.getbigdata());
string s=big1.getbigdata();
s=s.substr(,n-);
std::cout<<s<<std::endl;
//big1.getbigdata
system("pause");
}

3.

    1. 运行结果 
      结果后面会多出一个-号,可能是因为栈溢出或者某个地方初始化错误,利用了C++的substr方法处理了,在其中遇到一个问题,就是已经引入了 
      #include 
      String仍旧显示未定义的标识符,原因是没有写using namespace std;

C++实现大数据乘法的更多相关文章

  1. 大数据的乘法实现——C语言

    1大数据乘法的算法思路: 输入两个字符串,得到结果,例如:123456789*123456789: 思路:1)首先 123456789*1 = 9   18  27  36  45  54  63   ...

  2. UVA 10523 Very Easy!!!(大数据加法、乘法)

    题意:给出N,A,计算i*A^i(i=1~N)的和.1<=N<=30,0<=A<=15. 就是大数据运算,别的没什么,注意细节之处即可. 这题还要注意两个地方: 1.考虑A=0 ...

  3. POJ 1001 解题报告 高精度大整数乘法模版

    题目是POJ1001 Exponentiation  虽然是小数的幂 最终还是转化为大整数的乘法 这道题要考虑的边界情况比较多 做这道题的时候,我分析了 网上的两个解题报告,发现都有错误,说明OJ对于 ...

  4. 【大数据】Scala学习笔记

    第 1 章 scala的概述1 1.1 学习sdala的原因 1 1.2 Scala语言诞生小故事 1 1.3 Scala 和 Java  以及 jvm 的关系分析图 2 1.4 Scala语言的特点 ...

  5. MapReduce实现大矩阵乘法

    来自:http://blog.csdn.net/xyilu/article/details/9066973 引言 何 为大矩阵?Excel.SPSS,甚至SAS处理不了或者处理起来非常困难,需要设计巧 ...

  6. 17_常用API_第17天(包装类、System、Math、Arrays、大数据运算)_讲义

    今日内容介绍 1.基本类型包装类 2.System类 3.Math类 4.Arrays类 5.大数据运算 01基本数据类型对象包装类概述 *A:基本数据类型对象包装类概述 *a.基本类型包装类的产生 ...

  7. 大数据技术之_16_Scala学习_04_函数式编程-基础+面向对象编程-基础

    第五章 函数式编程-基础5.1 函数式编程内容说明5.1.1 函数式编程内容5.1.2 函数式编程授课顺序5.2 函数式编程介绍5.2.1 几个概念的说明5.2.2 方法.函数.函数式编程和面向对象编 ...

  8. 7、包装类、System、Math、Arrays、大数据运算

    基本类型封装 基本数据类型对象包装类概述 *A:基本数据类型对象包装类概述 *a.基本类型包装类的产生 在实际程序使用中,程序界面上用户输入的数据都是以字符串类型进行存储的.而程序开发中,我们需要把字 ...

  9. 大数据学习--day04(选择结构、循环结构、大数据java基础面试题)

    选择结构.循环结构.大数据java基础面试题 switch: 注意: byte short int char String(jdk1.7支持) 不能是 long float double boolea ...

随机推荐

  1. unix/linux进程详解

    技术分享 启动新进程 stdlib.hintsystem(const char *string)whichequals to "sh -c string" 替换进程映像unistd ...

  2. HDU 1054 Strategic Game(最小点覆盖+树形dp)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=106048#problem/B 题意:给出一些点相连,找出最小的点数覆盖所有的 ...

  3. File类的创建,删除文件

    File.Create(@"C:\Users\shuai\Desktop\new.txt"); Console.WriteLine("创建成功"); Conso ...

  4. ubuntu下安装 openssl 开发库

    ubuntu下安装 openssl 开发库 检查是否已安装openssl: sudo apt-get install openssl 如果已安装执行以下操作:sudo apt-get install ...

  5. Linux下SVN安装配置和使用中遇到的问题

    两个命令: svn info :显示版本库信息,svn的下载url等. svn co https://xxxxx/xxx   wodemulu   (通过我的目录制定co的文件夹) svn st:显示 ...

  6. NC反弹CMDSHELL提权总结

    Server-U等都不可以用的情况下.   一般都可思考用此方法不过这种方法, 只要对方装了防火墙, 或是屏蔽掉了除常用的那几个端口外的所有端口…   那么这种方法也失效了…. 1:通过shell将上 ...

  7. Visual Studio Online Integrations

                                                                                                         ...

  8. Random.nextint() 和Math.random()的区别

    Random.nextint() 和Math.random()的区别 Java代码   Random rand = new Random(); long startTime = System.nano ...

  9. A+B Again(在某个数中找大于m的最小约数)

    A+B Again Accepted : 15   Submit : 243 Time Limit : 1000 MS   Memory Limit : 65536 KB  题目描述 上次趣味赛小明的 ...

  10. python网络编程之最简单的单工通信

    tcp_server.py from socket import * server = socket(AF_INET, SOCK_STREAM) server.bind(('',12345)) ser ...