#4#6两个测试点报错,求条
查看原帖
#4#6两个测试点报错,求条
1576696
KatsuraJiu楼主2024/11/29 02:15

第四和第六两个测试点报错,求大佬帮忙看一下是哪里的问题

#include <stdio.h>
#include <string.h>

int num[100]={0};
int h=0;

int cot (char c);

int main()
{
	char i[200];
	int n=0;
	int t=0;
	int s=0;
	int k=0;
	
	scanf("%s",i);
	
	n=strlen(i);
	
	for(t=0;t<n;t++){
		if(i[t]>='0'&&i[t]<='9'){
			if(i[t-1]=='+'||i[t-1]=='-'||i[t-1]=='*'||i[t-1]=='*'){
				h++;
			}
			num[h]=(num[h])*10+(i[t]-48);
		}else if(i[t]=='.'){
			h++;
		}else if(i[t]=='+'||i[t]=='-'||i[t]=='*'||i[t]=='*'){
			k=t-1;
			if(i[k]=='.'){
				h--;
				s=cot(i[t]);
			}else{
				s=cot(i[t]);
			}
		}else if(i[t]=='@'){
			break;
		}
	}
	
	printf("%d",s);
	
	return 0;
}

int cot (char c)
{
	int T=h;
	int a=0;
	int sum=0;
	
	a=num[T];
	sum=num[T-1];
	
	if(c=='+'){
		sum=sum+a;
	}else if(c=='-'){
		sum=sum-a;
	}else if(c=='*'){
		sum=sum*a;
	}else if(c=='/'){
		sum=sum/a;
	}
	
	num[h]=0;
	
	h=T-1;
	num[h]=sum;
	
	return sum;
}
2024/11/29 02:15
加载中...