reeceli @ 2023-12-16 17:32:29
# include <stdio.h>
# include<stdlib.h>
# include <string.h>
# include<math.h>
#include<stdlib.h>
#include<stdio.h>
const char* plus(char arr[], char brr[]) {
long long crr[1000000];
long long drr[1000000];
long long err[1000000];
char grr[1000000] = "0";
int sz = strlen(arr);
int sz2 = strlen(brr);
for (int i = 0; i < sz; i++) {
crr[i] = arr[sz - i - 1] - 48;
}
/*printf("%d", crr[0]);*/
for (int i = 0; i < sz2; i++) {
drr[i] = brr[sz2 - i - 1] - 48;
}
/*printf("%d", drr[0]);*/
int min = 0;
int max;
if (sz < sz2)
min = sz;
else
min = sz2;
for (int i = 0; i < min; i++) {
err[i] = crr[i] + drr[i];
}
/*printf("%d", err[0]);*/
if (min == sz) {
for (int i = min; i < sz2; i++)
err[i] = drr[i];
max = sz2;
}
else {
for (int i = min; i < sz; i++) {
err[i] = crr[i];
max = sz;
}
}
for (int i = 0; i < max - 1; i++) {
if (err[i] > 9) {
err[i + 1] += err[i] / 10;
err[i] = err[i] % 10;
}
}
/*printf("%d", err[0]);*/
if (err[max - 1] > 9) {
err[max] = err[max - 1] / 10;
err[max - 1] = err[max - 1] % 10;
for (int i = 0; i <= max; i++)
grr[i] = err[max - i] + 48;
/* printf("%s", grr);*/
return grr;
}
for (int i = 0; i < max; i++)
grr[i] = err[max - i - 1] + 48;
/*printf("%s", grr);*/
return grr;
}
int main() {
int n;
scanf("%d", &n);
char arr[1000000] = "1";
char brr[1000000] = "2";
/*printf("%d", strlen(arr));
printf("%d", strlen(brr));*/
char crr[1000000] = "0";
for (int i = 2; i < n; i++) {
strcpy(crr, plus(arr, brr));
strcpy(arr, brr);
strcpy(brr, crr);
}
printf("%s", brr);
return 0;
}
by reeceli @ 2023-12-16 17:33:24
玄关求解
by vzcx_decipher @ 2023-12-16 18:33:40
函数内不能开很大的数组
你要感谢出题人没有造 n=1 的数据
by reeceli @ 2023-12-17 09:54:09
@GalilAR 我把数组放到外面定义果然就可以了,但是错了第六个点,第六个点就是 1,太有节目效果了。 谢谢大佬,已关。