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.123*105 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 (<100) 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 10100, 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.d1...dN*10^k" (d1>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

代码分析

这道题首先是考有效数字的表达,在自己进行测试检验是要注意输入数据是小数的情况,最后一个测试点输入数据是0.000和00.0000的情况,给出下面几组测试数据:
3 12300 12358.9
YES 0.123*10^5 1 12300 12358.9
YES 0.1*10^5 1 1.2300 1.23589
YES 0.1*10^1 5 1.2300 1.23589
NO 0.12300*10^1 0.12358*10^1 4 0.01234 0.012345
YES 0.1234*10^-1 5 0.01234 0.012345
NO 0.12340*10^-1 0.12345*10^-1 5 0.1234 0.12345
NO 0.12340*10^0 0.12345*10^0 0 0.11 0
YES 0.*10^0或者YES 0.0*10^0,都可以AC,测试点应该没有这个例子 1 0.1 0
NO 0.1*10^0 0.0*10^0 1 0.0 0.1
NO 0.0*10^0 0.1*10^0 1 0.0 0.000
YES 0.0*10^0 1 00.0 0.000
YES 0.0*10^0 4 00.0 0.000
YES 0.0000*10^0 5 00.0 0.000
YES 0.00000*10^0 1 05.0 5.000
YES 0.5*10^1 1 00.01 0.010
YES 0.1*10^-1
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
string a,b;
int n,t1,t2;
cin>>n>>a>>b;
auto it=find(a.begin(),a.end(),'.');
if(it!=a.end()){
t1=-(a.end()-1-it);
a.erase(it);
}
else t1=0;
int i;
for(i=0;i<a.size();i++){
if(a[i]!='0') break;
}
a=a.substr(i,a.size()-i);
it=find(b.begin(),b.end(),'.');
if(it!=b.end()){
t2=-(b.end()-1-it);
b.erase(it);
}
else t2=0;
for(i=0;i<b.size();i++)
if(b[i]!='0') break;
b=b.substr(i,b.size()-i);
t1+=a.size(); t2+=b.size();
if(a=="") t1=0;
if(b=="") t2=0;
if(a.size()<n) a.insert(a.end(),n-a.size(),'0');
if(b.size()<n) b.insert(b.end(),n-b.size(),'0');
if(t1==t2&&a.substr(0,n)==b.substr(0,n))
cout<<"YES 0."<<a.substr(0,n)<<"*10^"<<t1<<endl;
else
cout<<"NO 0."<<a.substr(0,n)<<"*10^"<<t1<<" 0."<<b.substr(0,n)<<"*10^"<<t2;
}

PAT 1060. Are They Equal的更多相关文章

  1. PAT 1060 Are They Equal[难][科学记数法]

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

  2. pat 1060. Are They Equal (25)

    题目意思直接,要求将两个数转为科学计数法表示,然后比较是否相同  不过有精度要求 /* test 6 3 0.00 00.00 test 3 3 0.1 0.001 0.001=0.1*10^-2 p ...

  3. 【PAT】1060 Are They Equal (25)(25 分)

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

  4. PAT 甲级 1060 Are They Equal

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

  5. 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 ...

  6. 1060 Are They Equal——PAT甲级真题

    1060 Are They Equal If a machine can save only 3 significant digits, the float numbers 12300 and 123 ...

  7. 1060 Are They Equal (25 分)

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

  8. 1060 Are They Equal (25分)

    1060 Are They Equal (25分) 题目 思路 定义结构体 struct fraction{ string f; int index; } 把输入的两个数先都转换为科学计数法,统一标准 ...

  9. 【PAT甲级】1060 Are They Equal (25 分)(需注意细节的模拟)

    题意: 输入一个正整数N(<=100),接着输入两个浮点数(可能包含前导零,对于PAT已经习惯以string输入了,这点未知),在保留N位有效数字的同时判断两个数是否相等,并以科学计数法输出. ...

随机推荐

  1. bzoj1106

    模拟+树状数组 先开始以为是先删距离最小的,这样可以减小上下的距离,然后觉得很难写,看码长很短,就看了题解,结果很奥妙 我们只考虑两种元素,就是如果像-a-b-a-b-这样的肯定得交换,如果像-a-b ...

  2. 60.extjs-布局 (在column布局中使用fieldset 和 在fieldset中使用column布局)

    转自:https://blog.csdn.net/snn1410/article/details/8817821/ 在标准的html中,需要把输入项都放到fieldset中,一次来显示分组结构.虽然E ...

  3. PCB SQL Server 触发器应用实例

    这里以实际例子对触发器的应用对触发器的理解与应用来得更实际 一.更新触发器(Update) 临时表:inserted表有数据(新数据)     Deleted表有数据(旧数据) 实例说明:当表更新时, ...

  4. SpringMvc快速入门之使用篇

    文章是为了结合工作需求来介绍springmvc,本文章只是切合实际的开发的场景对springmvc进行快速的入门介绍. 本篇文章不会对原理进行讲解.因为个人觉得有些对于新技术方面可以分为一下几个层次. ...

  5. zb的生日-------搜索 和 动态规划

    简单的贪心算法 : http://love-oriented.com/pack/P01.html  说实话 我是喜欢 动态规划的.......但是省赛迫在眉睫 , 只好先 学 搜索了  ,  赶紧   ...

  6. Android从Camera中获取图片的两种方法

    方法一: 此方法会由Camera直接产生照片回传给应用程序,但是返回的是压缩图片,显示不清晰 ? 1 2 3 4 5 6 try {      Intent cameraIntent = new In ...

  7. sqlyog注册码激活

    姓     名(Name):ttrar 序 列 号(Code):8d8120df-a5c3-4989-8f47-5afc79c56e7c 或者(OR) 姓     名(Name):ttrar 序 列 ...

  8. 【转】linux下vi命令大全

    转自:http://www.cnblogs.com/88999660/articles/1581524.html 进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi ...

  9. Combox两级联动会经常出现的错误

    例如: 当我们遇到这种情况:(下拉框的隐藏值和显示值皆为实体类进行绑定值时)下拉框的隐藏值并不能成功获取到. 我们就可以使用下面 的方案来解决 ok ,成功获取到隐藏值. 还有一个,附加解决方案:

  10. AOP注解不起作用的debug结果

    经过2天的调试,我发现AOP注解配置不起作用居然是表达式的错误导致的 在xml文件中配置的base-package有关,初步认为@PointCut只能使用base-package..*(..)这样的方 ...