您的位置:首页 > 其它

1060. Are They Equal (25)

2015-07-25 08:43 525 查看
测试用例中输入的数据不标准,例如000.123 000123 另外需要注意0的情况

#define _CRT_SECURE_NO_WARNINGS

#include<string>

#include<string.h>

#include<vector>

#include<map>

#include<stack>

#include<iostream>

#include<set>

#include<algorithm>

#include<stdio.h>

using namespace std;

bool isPrime(int num)

{

int range = sqrt(num) + 1;

for (int i = 2; i < range; i++)

if (num%i == 0)

return false;

return true;

}

void standard(string a,int &num,string &after)

{

num = 0;

after = "0.";

int i = 0;

while (a[i] == '0')

{

i++;

}

if (a[i] == '.')

{

for (i ++; i < a.size(); i++)

{

if (a[i] != '0')

{

after = after+ a.substr(i);

break;

}

else

{

num--;

}

}

if (after == "0.")

{

after += "0";

num = 0;

}

}

else

{

for (; i < a.size(); i++)

{

if (a[i] == '.')

{

after =after + a.substr(i + 1);

break;

}

else

{

num++;

after += a[i];

}

}

}

return;

}

int main()

{

int N;

cin >> N;

string a, b;

cin >> a >> b;

int num_a, num_b;

string after_a , after_b;

standard(a, num_a, after_a);

standard(b, num_b, after_b);

while (after_a.size() < N + 2)

{

after_a += "0";

}

while (after_b.size() < N + 2)

{

after_b += "0";

}

bool btrue = true;

if (num_a != num_b)

{

btrue = false;

}

else

{

if (after_a.substr(0, N + 2) != after_b.substr(0, N + 2))

btrue = false;

}

if (btrue)

{

printf("YES %s*10^%d", after_a.substr(0, N + 2).c_str(), num_a);

}

else

{

printf("NO %s*10^%d %s*10^%d", after_a.substr(0, N + 2).c_str(), num_a, after_b.substr(0, N + 2).c_str(), num_b);

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: