求解,为何本地的测试结果和在线IDE上的不同?
查看原帖
求解,为何本地的测试结果和在线IDE上的不同?
474228
koppe楼主2021/4/17 16:52

本地样例和自测以及下载的数据都在本地能过,为什莫上了洛谷就炸了,裂开。 求大佬指点.

char str[30];
int x=0;
int y=0;
void g(char* s){
	int i=0;
	int loc=1;
	int len=strlen(s);
	x=0;y=0;
	char* p=strstr(s," ");//定位空格 
for(i=p-s+1;s[i]!=' ';i++){
	loc++;
}
int k=loc-1;
for(i=p-s+1;i<p-s+loc;i++){
	 x+=(s[i]-'0')*pow(10,k-1);//计算数字 
	 k--;
}
for(i=p-s+loc+1;i<len;i++){
	
	y+=(s[i]-'0')*pow(10,len-i-1);//同上 
}
}
void f(char* u){
	x=0;y=0;
	char* p=strstr(u," ");
int k=p-u;
int i;
int len=strlen(u);
	for(i=0;i<p-u;i++){
		x+=(u[i]-'0')*pow(10,k-1);
		k--;
	}for(i=p-u+1;i<strlen(u);i++){
		y+=(u[i]-'0')*pow(10,len-i-1);
	}
}
int h(int k){
	int flag;
		int cnt=0;
	if(k<0){
		flag=1;
	}else if(k==0){
		flag=0;
		cnt=1;
	}else {
		flag=0;
	}
	

	while(k){
		k/=10;
		cnt++;
	}
	return cnt+flag;//计算位数的函数 
}
int main()
{
int i=0;
int n;
int flag=0;
int bia=0;
scanf("%d",&n);
int j=0;
getchar();
for(i=0;i<n;i++){
	gets(str);
	getchar;
	switch(str[0]){
		case 'a':  g(str);
		end1:
		printf("%d+%d=%d\n",x,y,x+y);printf("%d\n",h(x)+h(y)+2+h(x+y));flag=1;break;
		case 'c':g(str);
		end2:
		printf("%d*%d=%d\n",x,y,x*y);printf("%d\n",h(x)+h(y)+2+h(x*y));flag=2;break;
		case 'b':g(str);
		end3:
			printf("%d-%d=%d\n",x,y,x-y);
		printf("%d\n",h(x)+h(y)+h(x-y)+2);flag=3;break;
		default:f(str);if(flag==1){
			goto end1;
		}else if(flag==2){
			goto end2;
		}else{
			goto end3;
		}
	}
}

	return 0;
 } 

2021/4/17 16:52
加载中...