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;
}
#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;
}
相关文章推荐
- 工作日志2014-08-27
- 消息系统Kafka介绍
- NSString以及NSArray的习题练习
- 快快快!27个提升效率的iOS开源库推荐
- SI编程器
- 黑马程序员——Java基础-异常
- Android 权限大全
- spring task定时器的运用
- mysql安装或配置
- Android中常用单位(dpi、px、dp、sp)
- 智商是老出来的
- uva11361(数论DP)
- 移动互联网的产品谍照
- asp.net access连接
- 关闭win10推送服务的两种解决办法
- 字典树
- Hadoop运维操作
- error: stray ‘\342’ in program
- 强大的管理构建工具之maven
- Android 流量统计TrafficStats总结