如何在源代码基础上加入负数运算
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
#define maxn 10
#define N 100005
int a[10000000];
int pp = 0;
struct Sqlist
{
int data;
struct Sqlist* next, * before;
};
struct Sqlist* r1, * str1, * s1, * s11, * r2, * str2, * s2, * s22;
void ab()
{
char s[N], ss1[N], ss2[N];
int len1, len2, ans = 0, flag = 0, i;
scanf("%s%s", ss1, ss2);
len1 = strlen(ss1);
len2 = strlen(ss2);
r1 = (struct Sqlist*)malloc(sizeof(struct Sqlist));
r1->before = NULL;
r2 = (struct Sqlist*)malloc(sizeof(struct Sqlist));
r2->before = NULL;
str1 = r1;
for (i = len1 - 1; i >= 0; --i)
{
s1 = (struct Sqlist*)malloc(sizeof(struct Sqlist));
s1->data = ss1[i] - '0';
s1->next = NULL;
s1->before = str1;
str1->next = s1;
str1 = str1->next;
}
s1 = (struct Sqlist*)malloc(sizeof(struct Sqlist) );
s1->data = 0;
s1->next = NULL;
s1->before = str1;
str1->next = s1;
str1 = str1->next;
str2 = r2;
for (i = len2 - 1; i >= 0; --i)
{
s2 = (struct Sqlist*)malloc(sizeof(struct Sqlist));
s2->data = ss2[i] - '0';
s2->next = NULL;
s2->before = str2;
str2->next = s2;
str2 = str2->next;
}
for (i = 0; i <= len1 - len2; ++i)
{
s2 = (struct Sqlist*)malloc(sizeof(struct Sqlist));
s2->data = 0;
s2->next = NULL;
s2->before = str2;
str2->next = s2;
str2 = str2->next;
}
ans = 0;
str1 = r1->next;
str2 = r2->next;
for (i = 0; i <= len1; ++i)
{
ans = ans + str1->data + str2->data;
str1->data = ans % 10;
ans /= 10;
str1 = str1->next;
str2 = str2->next;
}
flag = 0;
ans = 0;
str1 = r1->next;
while (1)
{
if (str1->next == NULL) break;
str1 = str1->next;
}
while (str1 != NULL)
{
if (str1->data != 0)
flag = 1;
if (flag)
{
ans++;
a[pp] = str1->data;
pp++;
}
str1 = str1->before;
if (str1->before == NULL) break;
}
printf("\n");
}
int main()
{
memset(a, 0, sizeof(a));
cout << "请输入数据:" << endl;
ab();
int xx = pp % 4;
int pan = 0;
cout << "输出结果为:" << endl;
for (int i = 0; i < pp - 4; i++)
{
cout << a[i];
pan++;
if (i == xx - 1)
{
cout << ",";
pan = 0;
}
if (pan % 4 == 0 && pan != 0) cout << ","; //四位一输出
}
for (int i = pp - 4; i < pp; i++)
cout << a[i];
cout << endl;
return 0;
}