HDU2054 A = B?

Source: Internet
Author: User

A very difficult question seems to be violent .. It was easy to use _ int64, wa, and then found that it was not that simple.

1. Unified Positive and Negative Numbers

2. Remove pilot zero

3. Remove the 0 at the end of the decimal point.

3. All kinds of pits indicated by 0 + 0-0 + 0.00-0.000 are yes...

Do not look down on questions .. ORZ


[Cpp]
# Include <iostream>
# Include <string>
# Include <cstdio>
# Include <ctype. h>
Using namespace std;
 
Int main ()
{
String a, B;
String blank = "";
While (cin> a> B)
{
Bool a0 = 1, b0 = 1;
// 0, preventing 0.00-0 + 0.000 + 00. 000 ......
For (int I = 0; I <a. length (); I ++)
{
If (a [I]! = '0' & a [I]! = '.' & A [I]! = '+' & A [I]! = '-')
{
A0 = 0;
Break;
}

}
For (int I = 0; I <B. length (); I ++)
{
If (B [I]! = '0' & B [I]! = '.' & B [I]! = '+' & B [I]! = '-')
{
B0 = 0;
Break;
}

}
If (a0 = 1 & b0 = 1)
{
Cout <"YES" <endl;
Break;
}
// 1-prevent + 0
If (isdigit (a [0])
A. insert (0, "+ ");
If (isdigit (B [0])
B. insert (0, "+ ");

Int posa = a. length ()-1;
Int posb = B. length ()-1;
Int befzeroa = 0, befzerob = 0;


For (int j = 1; j <posa; j ++)
{
If (a [j] = '0 ')
Continue;
Else
{
Befzeroa = J-1;
Break;
}

}
For (int j = 1; j <posb; j ++)
{
If (B [j] = '0 ')
Continue;
Else
{
Befzerob = J-1;
Break;
}

}
// 2-prevent 009.7 9.7
A. erase (1, befzeroa); // correct deletion usage
B. erase (1, befzerob );

Int lastzeroa = a. length ();
Int lastzerob = B. length ();

For (int I = 1; I <a. length (); I ++)
{
If (a [I] = '.')
Posa = I;
}
For (int j = 1; j <B. length (); j ++)
{
If (B [j] = '.')
Posb = j;
}

For (int p = a. length ()-1; p> posa; p --)
{
If (a [p] = '0 ')
{
A. erase (p, 1 );
}
Else
{
Break;
}
}

For (int t = B. length ()-1; t> posb; t --)
{
If (B [t] = '0 ')
{
B. erase (t, 1 );
}
Else
{
Break;
}
}


// 3-prevent 3.0 --- 3
If (a [a. length ()-1] = '.')
A. erase (a. length ()-1, 1 );
If (B [B. length ()-1] = '.')
B. erase (B. length ()-1, 1 );


// Cout <a <"" <B <endl;
If (a = B)
Cout <"YES" <endl;
Else
Cout <"NO" <endl;



}

Return 0;
}

# Include <iostream>
# Include <string>
# Include <cstdio>
# Include <ctype. h>
Using namespace std;

Int main ()
{
String a, B;
String blank = "";
While (cin> a> B)
{
Bool a0 = 1, b0 = 1;
// 0, preventing 0.00-0 + 0.000 + 00. 000 ......
For (int I = 0; I <a. length (); I ++)
{
If (a [I]! = '0' & a [I]! = '.' & A [I]! = '+' & A [I]! = '-')
{
A0 = 0;
Break;
}

}
For (int I = 0; I <B. length (); I ++)
{
If (B [I]! = '0' & B [I]! = '.' & B [I]! = '+' & B [I]! = '-')
{
B0 = 0;
Break;
}

}
If (a0 = 1 & b0 = 1)
{
Cout <"YES" <endl;
Break;
}
// 1-prevent + 0
If (isdigit (a [0])
A. insert (0, "+ ");
If (isdigit (B [0])
B. insert (0, "+ ");

Int posa = a. length ()-1;
Int posb = B. length ()-1;
Int befzeroa = 0, befzerob = 0;


For (int j = 1; j <posa; j ++)
{
If (a [j] = '0 ')
Continue;
Else
{
Befzeroa = J-1;
Break;
}

}
For (int j = 1; j <posb; j ++)
{
If (B [j] = '0 ')
Continue;
Else
{
Befzerob = J-1;
Break;
}

}
// 2-prevent 009.7 9.7
A. erase (1, befzeroa); // correct deletion usage
B. erase (1, befzerob );
 
Int lastzeroa = a. length ();
Int lastzerob = B. length ();

For (int I = 1; I <a. length (); I ++)
{
If (a [I] = '.')
Posa = I;
}
For (int j = 1; j <B. length (); j ++)
{
If (B [j] = '.')
Posb = j;
}

For (int p = a. length ()-1; p> posa; p --)
{
If (a [p] = '0 ')
{
A. erase (p, 1 );
}
Else
{
Break;
}
}

For (int t = B. length ()-1; t> posb; t --)
{
If (B [t] = '0 ')
{
B. erase (t, 1 );
}
Else
{
Break;
}
}
 
 
// 3-prevent 3.0 --- 3
If (a [a. length ()-1] = '.')
A. erase (a. length ()-1, 1 );
If (B [B. length ()-1] = '.')
B. erase (B. length ()-1, 1 );


// Cout <a <"" <B <endl;
If (a = B)
Cout <"YES" <endl;
Else
Cout <"NO" <endl;



}
 
Return 0;
}


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.