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. Sql2005常用函数大全

    --聚合函数use pubsgoselect avg(distinct price) --算平均数from titleswhere type='business'go use pubsgoselect ...

  2. algorithm库———count&&countif

    algorithm头文件定义了一个count的函数,其功能类似于find.这个函数使用一对迭代器和一个值做参数,返回这个值出现次数的统计结果. 编写程序读取一系列int型数据,并将它们存储到vecto ...

  3. 洛谷P2516 [HAOI2010]最长公共子序列

    题目描述 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X="x0,x1,-,xm-1",序列Y=& ...

  4. bzoj 2276 [ Poi 2011 ] Temperature —— 单调队列

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2276 维护 l 递减的单调队列,队头的 l > 当前的 r 就出队,因为不能是连续一段 ...

  5. openstack instance resize to rebuild

  6. 微信小程序之商品发布+编辑功能(多图片上传功能)

    小程序的商品发布页面:功能有多图片上传 遇到的问题记录一下:1.uploadFile成功之后返回的参数是json字符串,一定要用JSON.parse转换为object格式 2.因为商品发布和编辑都是在 ...

  7. JavaSE综合项目演练

    光阴似箭日月如梭,大家学习已经有了一段时间了,转眼间,从刚开始如何配置JDK已经到了现在快学完网络编程了.学了这么多,眼看就要进入下一个阶段了,数据库编程了,那么在进入下个阶段前,我们来完成一个综合性 ...

  8. Java中从控制台输入的三种方式

    我们最熟悉的从控制台读取一个字符或者一个字符串都知道用Scanner,那么除了Scanner还有没有其他的呢,答案是有的,我们来看看. System.in.read() System.in.read( ...

  9. 大圆那些事 LIBRARY_PATH和LD_LIBRARY_PATH环境变量的区别

    LIBRARY_PATH和LD_LIBRARY_PATH环境变量的区别 LIBRARY_PATH和LD_LIBRARY_PATH是Linux下的两个环境变量,二者的含义和作用分别如下: LIBRARY ...

  10. android 二维码 扫描,生成,竖屏

    最近公司有用到二维码,生成,扫描,所以学习了一下,和大家分享: demo 见下面链接,已经改成竖屏: http://download.csdn.net/detail/q610098308/868101 ...