请问编译器正常,平台显示 "编译错误"怎么回事?
查看原帖
请问编译器正常,平台显示 "编译错误"怎么回事?
1340042
yaoxinmail楼主2024/5/7 16:43

/tmp/compiler_lira2tui/src: In function ‘int add(char*, char*, char*)’: /tmp/compiler_lira2tui/src:7:9: 错误:‘strrev’ was not declared in this scope; did you mean ‘strsep’? 7 | strrev(s1); | ^~~~~~ | strsep

代码如下:

#include<iostream>
#include<cstring>
using namespace std;
#define maxn 10050
int add(char* s1, char* s2, char* buf){
	if (strlen(s1) > strlen(s2)) return add(s2,s1,buf);
	strrev(s1);
	strrev(s2);
	char* p=s1;
	char* q=s2;
	char* r=buf;
	int cx = 0;
	
	while(*p){
		int t = (*p -'0') + (*q-'0') +cx;
		*r = t % 10 +'0';
		cx = t / 10;
		p++; q++; r++;
	}
	while(*q){
		int t = *q-'0' + cx;
		*r = t % 10 +'0';
		cx = t / 10;
		q++; r++;
	}
	if(cx==1) {
	*r = '1';
	r++;
	}
	*r='\0';
	strrev(buf);
	return 0;
}

int main(){
	char  a[maxn],b[maxn],c[maxn];
	memset(a,0,maxn);	memset(b,0,maxn);	memset(c,0,maxn);
	int n;
	cin>>n;
	a[0]='2' ;
	b[0]='1';
	for(int i=3; i<=n ; i++ ){
	strcpy(c,a);
	add(b,c,a);
	strcpy(b,c);
	}
	cout<<a<<endl;
	return 0;
}
2024/5/7 16:43
加载中...