If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0 with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are supposed to tell if they are treated equal in that machine.

Input Specification:

Each input file contains one test case which gives three numbers N, A and B, where N (<) is the number of significant digits, and A and B are the two float numbers to be compared. Each float number is non-negative, no greater than 1, and that its total digit number is less than 100.

Output Specification:

For each test case, print in a line YES if the two numbers are treated equal, and then the number in the standard form 0.d[1]...d[N]*10^k (d[1]>0 unless the number is 0); or NO if they are not treated equal, and then the two numbers in their standard form. All the terms must be separated by a space, with no extra space at the end of a line.

Note: Simple chopping is assumed without rounding.

Sample Input 1:

3 12300 12358.9

Sample Output 1:

YES 0.123*10^5

Sample Input 2:

3 120 128

Sample Output 2:

NO 0.120*10^3 0.128*10^3

其实这道题的难度在于得到这个数的幂次
 #include <iostream>
#include <string>
using namespace std;
string A, B;//注意,10^100超出double的范围,只能使用字符串来存取
int N;
int dealString(string &str)//数据预处理,返回数据位数
{
int k = str.find('.');//找到小数点
if (k != -)
{
str.erase(k, );//删除小数点
if (str[] == '')
{
k = ;
str.erase(, );//删除第一个0
}
}
else//没有小数
{
if (str != "")
k = str.length();
else
{
k = ;
str.erase(, );//删除第一个0
}
}
while (!str.empty() && str[] == '')
{
str.erase(, );//输出前面的0
k--;//比如0.000128 = 0.128*10^-3
}
if (str.empty())//这个数就是0
k = ;
while (str.length() < N)
str += "";//位数不够0来凑
return k;
} int main()
{
cin >> N >> A >> B;
//使用k1,k2来得到A,B的位数
int k1, k2;
k1 = dealString(A);
k2 = dealString(B);
A.assign(A.begin(), A.begin() + N);//取前N位
B.assign(B.begin(), B.begin() + N);
if (A == B && k1 == k2)
{
cout << "YES ";
cout << "0." << A << "*10^" << k1 << endl;
}
else
{
cout << "NO ";
cout << "0." << A << "*10^" << k1 << " ";
cout << "0." << B << "*10^" << k2 << endl;
}
return ;
}

PAT甲级——A1060 Are They Equal的更多相关文章

  1. PAT 甲级 1060 Are They Equal

    1060. Are They Equal (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue If a ma ...

  2. pat 甲级 1053. Path of Equal Weight (30)

    1053. Path of Equal Weight (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  3. PAT 甲级 1060 Are They Equal (25 分)(科学计数法,接连做了2天,考虑要全面,坑点多,真麻烦)

    1060 Are They Equal (25 分)   If a machine can save only 3 significant digits, the float numbers 1230 ...

  4. PAT 甲级 1053 Path of Equal Weight (30 分)(dfs,vector内元素排序,有一小坑点)

    1053 Path of Equal Weight (30 分)   Given a non-empty tree with root R, and with weight W​i​​ assigne ...

  5. PAT甲级——A1053 Path of Equal Weight

    Given a non-empty tree with root R, and with weight W​i​​ assigned to each tree node T​i​​. The weig ...

  6. PAT甲级1060 Are They Equal【模拟】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805413520719872 题意: 给定两个数,表示成0.xxxx ...

  7. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  8. 【转载】【PAT】PAT甲级题型分类整理

    最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...

  9. PAT甲级题分类汇编——树

    本文为PAT甲级分类汇编系列文章. AVL树好难!(其实还好啦~) 我本来想着今天应该做不完树了,没想到电脑里有一份讲义,PPT和源代码都有,就一遍复习一遍抄码了一遍,更没想到的是编译一遍通过,再没想 ...

随机推荐

  1. 尚学python课程---13、python基础语法

    尚学python课程---13.python基础语法 一.总结 一句话总结: legend2系统使我能够快速掌握一门语法,特别有用 pass 语句:空语句:是为了保持程序结构的完整性  :作用:比如: ...

  2. error C2220: warning treated as error - no object file generated的处理方法

    WDK/DDK中掉 error C2220: warning treated as error - no 'object' file generated 2009-04-01 15:54 网上搜索而来 ...

  3. VS2010-MFC(常用控件:组合框控件Combo Box)

    转自:http://www.jizhuomi.com/software/189.html 上一节讲了列表框控件ListBox的使用,本节主要讲解组合框控件Combo Box.组合框同样相当常见,例如, ...

  4. dart 异步

    使用异步有两种方法 then 或者 async/await. async/await 方法更易于理解,

  5. svn+post-commit实现自动部署(转)

    一.安装 #yum install subversion 检查是否安装了svn #subversion –v 创建svn库和对应的目录 #mkdir /svn/www.test.com #svnadm ...

  6. selenium基础(元素定位)

    selenium的帮助文档: https://selenium-python.readthedocs.io/api.html#module-selenium.common.exceptions 目前支 ...

  7. iOS开发系列-NSURLSession

    概述 NSURLSession是从iOS7开始出现的.NSURLSession比NSURLConnection简单很多并且避免了很多坑,因此目前公司项目大部分由NSURLConnection过度为NS ...

  8. 2019-8-31-C#-如何给-ValueTuple-返回值添加注释

    title author date CreateTime categories C# 如何给 ValueTuple 返回值添加注释 lindexi 2019-08-31 16:55:58 +0800 ...

  9. linux 命令 find与rm实现查找并删除目录或文件

    504  find /Volumes/WD/data/data/sg3d/server -type d |grep .svn 505  find /Volumes/WD/data/data/sg3d/ ...

  10. Django如何自定义漂亮的404页面

    目录 在templates 中添加404.html 修改settings.py 在templates 中添加404.html <!DOCTYPE html PUBLIC "-//W3C ...