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<iostream>
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]==' ')
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]=' ';
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<<a<<endl;
return a;
}
int main()
{
while(cin>>bank1>>bank2)
{
bool sign=true,sign1=false;
x=change(bank1);
y=change(bank2);
//cout<<bank1<<endl;
//cout<<bank2<<endl;
for(int i=x,j=y;;i++,j++)
{
if(bank1[i]==' ')
{
if(bank2[i]!=' ')
sign=false;
break;
}
if(bank1[i]!=bank2[j])
{
//cout<<"12:"<<bank1[i]<<bank2[i]<<endl;
sign=false;
}
}
//cout<<sign<<endl;
if(bank1[0]==bank2[0])
sign1=true;
else if(bank1[0]=='+'&&bank2[0]>='0'&&bank2[0]<='9')
sign1=true;
else if(bank2[0]=='+'&&bank1[0]>='0'&&bank2[0]<='9')
sign1=true;
cout<<(sign&&sign1?"YES":"NO")<<endl;
}
}