CodeAtlantis @ 2022-07-08 23:08:14
有大佬帮帮忙吗?
#include<bits/stdc++.h>
using namespace std;
int main(){
char a1[2005], b1[2005];
int a[2005], b[2005], c[2005];
int lena, lenb, lenc, x;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
gets(a1);gets(b1);
lena = strlen(a1);lenb = strlen(b1);
for(int i = 0; i <= lena-1; i++)
a[lena-i] = a1[i] - 48;
for(int i = 0; i <= lenb-1; i++)
b[lenb-i] = b1[i] - 48;
for(int i = 1; i <= lena; i++){
x = 0;
for(int j = 1; j <= lenb; j++){
c[i+j-1]=a[i]*b[j]+x+c[i+j-1];//
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lenb]=x;
}
lenc = lena + lenb;
while(c[lenc]==0&&lenc>1)
lenc--;
for(int i = lenc; i >= 1; i--)
cout << c[i];
cout << endl;
return 0;
}
CE评测
https://www.luogu.com.cn/record/78830351
by Lunar_Hjj @ 2022-07-08 23:16:37
gets()的问题,洛谷上交不了的
by Lunar_Hjj @ 2022-07-08 23:19:07
编译信息节选:‘gets’ was not declared in this scope;
翻译:在此作用域中gets未定义
by harvey2019 @ 2022-07-08 23:40:17
gets ……
by Coros_Trusds @ 2022-07-09 07:25:55
#include<bits/stdc++.h>
using namespace std;
int main(){
char a1[2005], b1[2005];
int a[2005], b[2005], c[2005];
int lena, lenb, lenc, x;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
fgets(a1,2005,stdin);fgets(b1,2005,stdin);
lena = strlen(a1);lenb = strlen(b1);
for(int i = 0; i <= lena-1; i++)
a[lena-i] = a1[i] - 48;
for(int i = 0; i <= lenb-1; i++)
b[lenb-i] = b1[i] - 48;
for(int i = 1; i <= lena; i++){
x = 0;
for(int j = 1; j <= lenb; j++){
c[i+j-1]=a[i]*b[j]+x+c[i+j-1];//
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lenb]=x;
}
lenc = lena + lenb;
while(c[lenc]==0&&lenc>1)
lenc--;
for(int i = lenc; i >= 1; i--)
cout << c[i];
cout << endl;
return 0;
}
by Coros_Trusds @ 2022-07-09 07:26:40
你应该写错了
by CodeAtlantis @ 2022-07-09 19:23:38
@Coros_Trusds 谢谢大佬指教
by CodeAtlantis @ 2022-07-09 19:27:46
@Coros_Trusds
大佬 改成这个全WA了https://www.luogu.com.cn/record/78912107
自己用cin输入却只有最后一个点WA https://www.luogu.com.cn/record/78911767
by Coros_Trusds @ 2022-07-09 20:42:56
@极客666 抱歉原因是 fgets
读入会把换行符 \n
也一起读入导致奇奇怪怪的错误
仔细看了下你的数组开小了
AC 代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 4e4 + 5;
char a1[N], b1[N];
int a[N], b[N], c[N];
int main(){
int lena, lenb, lenc, x;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
cin >> a1 >> b1;
lena = strlen(a1);lenb = strlen(b1);
for(int i = 0; i <= lena-1; i++)
a[lena-i] = a1[i] - 48;
for(int i = 0; i <= lenb-1; i++)
b[lenb-i] = b1[i] - 48;
for(int i = 1; i <= lena; i++){
x = 0;
for(int j = 1; j <= lenb; j++){
c[i+j-1]=a[i]*b[j]+x+c[i+j-1];//
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lenb]=x;
}
lenc = lena + lenb;
while(c[lenc]==0&&lenc>1)
lenc--;
for(int i = lenc; i >= 1; i--)
cout << c[i];
cout << endl;
return 0;
}
by CodeAtlantis @ 2022-07-09 22:07:14
@Coros_Trusds 太感谢了