标题:写入位置 0x0000000000000000 时发生访问冲突。怎么改过来啊,新手求助
取消只看楼主
我们要在一起
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-12-14
 问题点数:0 回复次数:0 
写入位置 0x0000000000000000 时发生访问冲突。怎么改过来啊,新手求助
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
using namespace std;
const int Max = 100;
class dazhengshu
{
public:
string addition(string &, string &);
void showjieguo();
private:
string outcome;
};
string dazhengshu::addition(string &str1, string &str2)
{
int x,y,mark = 0;
string str;
vector<int> num1(Max+10);
vector<int> num2(Max+10);
if(str1[0] == '-'&&str2[0] == '-')
{
mark = 1;
str1.erase(0,1);
str2.erase(0,1);
}
else if(str1[0] == '-'&&str2[0] != '-')
{
str1.erase(0,1);
outcome = addition(str2,str1);
return outcome;
}
else if(str1[0] != '-'&&str2[0] == '-')
{
str2.erase(0,1);
outcome =addition(str1,str2);
return outcome;
}
y = 0;
for(x = str1.size()-1; x >= 0; x--)
num1[y++] = str1[x]-'0';
y = 0;
for(x = str2.size()-1; x >= 0; x--)
num2[y++] = str2[x]-'0';
for(x = 0; x <= Max; x++)
{
num1[x] += num2[x];
if(num1[x]>=10)
{
num1[x] -= 10;
num1[x+1]++;
}
}
bool isBeginOutput = false;
for(x = Max; x >= 0;x--)
{
if(num1[x] != 0)
isBeginOutput = true;
if(isBeginOutput)
str += num1[x]+48;
}
if(!isBeginOutput)
str = "0";
if(mark)
str.insert(0,"-");
outcome = str;
return outcome;
}
void dazhengshu::showjieguo()
{
cout << outcome << endl;
}
int main()
{
string str1;
string str2;
dazhengshu a;
string store[10000];
char operation;
int m;
cin>>m;
for(int i=0;i<m;i++)
{
    (cin>>str1>>operation>>str2);
switch(operation)
{
case '+': store[i]=a.addition(str1,str2); ;break;
case '0':  exit(1);
}
}
for(int i=0;i<m;i++)
{
cout << store[i]<<endl;
}
system("pause");
return 0;
}

搜索更多相关主题的帖子: include private addition public 
2016-12-14 15:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-472401-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.344628 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved