Why don't you simply take input into ints instead of strings and get rid of cut()?
Also, the problem statement says nothing about printing the input back out. It just says to print either "YES" or "NO".
Because these inputs may be 0000010 and 10,in this case,I chose strings
and sorry I posted it incorrectly in output .I've re-edited it,but it's also a wrong answer.
By the sound of it you have to choose the appropriate variable type that gives the greatest range to accommodate all versions of the generic type. eg use double where double and float is possible.
#include <iostream>
#include <string>
usingnamespace std;
string a, b;
char t;
long i;
int
main (void) {
while (cin >> a >> b) {
if (a.find(".") != a.npos) {
i = a.length();
while ((a[--i] == '0' || a[i] == '.') && i > 0) {
t = a[i];
a.erase(i, 1);
if (t == '.') break;
}
}
if (b.find(".") != b.npos) {
i = b.length();
while ((b[--i] == '0' || b[i] == '.') && i > 0) {
t = b[i];
b.erase(i, 1);
if (t == '.') break;
}
}
while ((a[0] == '0') && a.length() > 1) {a.erase(0, 1);}
while ((b[0] == '0') && b.length() > 1) {b.erase(0, 1);}
if (a == ".") a = "0";
if (b == ".") b = "0";
if (a == b) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
it's our homework.when I handed in,it told me that I was wrong:(
someone else told me that the two numbers may be over 5000 bits,how can I deal with that?
Play it the way you see it Alphar. Nobody here can read minds. You have a number of alternative pieces of advice and you need to use your own judgement on which one(s), if any, suit your solution. Best wishes. :)