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. Linux权限命令chmod

    一.Linux chmod命令修改文件和文件目录权限(默认情况下只有root用户才能使用).命令格式:chmod+修改内容+要修改的文件或者 目录 或者 chmod -R 修改内容 要修改的文件或者 ...

  2. spring加载属性配置文件内容

    在spring中提供了一个专门加载文件的类PropertyPlaceholderConfigurer,通过这个类我们只需要给定需要加载文件的路径就可以 通过该类加载到项目,但是为了后面在程序中需要使用 ...

  3. Spring - 整合MyBatis

    目的: 使用 Spring 容器用单例模式管理 MyBatis 的 sqlSessionFactory : 使用 Spring 管理连接池.数据源等: 将 Dao / Mapper 动态代理对象注入到 ...

  4. 【CF888G】Xor-MST

    题目 也不是很知道为什么这道题要和某\(B\)姓算法扯上关系 首先有一个非常显然基于那个\(B\)姓算法的做法,每次启发式合并\(trie\)即可,复杂度是\(O(n\ logn\ loga_i)\) ...

  5. shell脚本练习02--求字符串的长度

    ######################################################################### # File Name: -.sh # Author ...

  6. 笔记:Python异常处理与程序调试

    Python异常处理与程序调试 Python提供了强大的异常处理机制,通过捕获异常可以提高程序的健壮性.异常处理还具有释放对象,中止循环的运行等作用.在程序运行的过程中,如果发生了错误,可以返回事先约 ...

  7. vue倒计时:天时分秒

    data数据定义 data () { return { curStartTime: '2019-07-31 08:00:00', day: '0', hour: '00', min: '00', se ...

  8. JavaWeb中请求转发和请求重定向的区别

    针对于JavaWeb中请求与重定向的一个cheatsheep: 1.转发 1)完成一次转发,用户浏览器发送一次请求 2)转发之后,浏览器URL地址栏不改变(服务器帮忙完成) 3)请求域中数据不丢失 4 ...

  9. LUOGU P4163 [SCOI2007]排列

    传送门 解题思路 首先我们发现这道题s的长度很小,所以考虑点暴力的做法,状压dp或搜索.本蒟蒻搜索永远调不对,所以就写了个状压dp.因为所有s里的数都要出现一次,并且最后的答案是要求整除,那么我们设d ...

  10. Mac OS X 下有关adb相关问题

    一.什么是adb? ADB的全称是Android Debug Bridge,用来调试Android程序的,白话点就是debug工具! 位置:一般下载Android的SDK时候在platform-too ...