杭电OJ-2054_A == B ?

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 76226    Accepted Submission(s): 12101


Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
 
环境:
第一次在ubuntu下用VSCode编辑,g++编译;

调了3个小时,到最后都没ac的一题(找不出哪错了)。我写在这记录一下

1.一开始的时候去掉浮点数的后面的无效0,若小数点后面全是0,则小数点一起去掉(WA)

2.去掉前导0(WA)

3.假设前面有符号(WA)

4.以为数组开小了,改成bank[1000005]。(WA)

5.崩溃了,过段时间再来看吧。

代码如下,求大神指导

#include
using namespace std;
char bank1[1000005],bank2[1000005];
int x,y;
int change(char *bank)
{
	bool sign=false;
	int i;
	for(i=0;;i++)					//fu dian shu pan duan
	{
		if(bank[i]=='\0')
			break;
		else if(bank[i]=='.')
			sign=true;
	}
	if(sign)						//qu chu xiao shu dian hou mian 0
	{
		for(int j=i-1;j>=0;j--)
		{
			if(bank[j]=='0'||bank[j]=='.')
				bank[j]='\0';
			else
				break;
		}
	}
	int a=0;
	for(int i=0;;i++)					//qu chu qian dao 0 he + -
	{
		if(bank[i]=='0'||bank[i]=='+'||bank[i]=='-')
		 a++;
		 else
		 break;
	}
	//cout<>bank1>>bank2)
	{
			bool sign=true,sign1=false;
			x=change(bank1);
			y=change(bank2);
			//cout<='0'&&bank2[0]<='9') 
				sign1=true;
			else if(bank2[0]=='+'&&bank1[0]>='0'&&bank2[0]<='9')
				sign1=true;
			cout<<(sign&&sign1?"YES":"NO")<




你可能感兴趣的:(HDU)