Comment ajouter un nombre négatif à ce code

Questions et réponses du rseoc 2021-12-30 13:55:32 阅读数:952

comment ajouter nombre gatif ce
Le phénomène rencontré par le problème et le contexte dans lequel il s'est produit

Comment ajouter des opérations négatives au code source

Codes liés au problème,Ne collez pas la capture d'écran
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h>#include<iostream>#include<string.h>#include<stdlib.h>using namespace std;#define maxn 10#define N 100005int 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 << "Veuillez saisir les données:" << endl; ab(); int xx = pp % 4; int pan = 0; cout << "Le résultat est:" << 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 << ","; // Quatre bits une sortie } for (int i = pp - 4; i < pp; i++) cout << a[i]; cout << endl; return 0;}
版权声明:本文为[Questions et réponses du rseoc]所创,转载请带上原文链接,感谢。 https://primo.wiki/2021/12/202112231459356643.html