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,学习到了关于web的内容。

    然而在win10中IIS发布CGI脚本的时候遇到了各种各样的问题. 如ISAPI和CGI限制,权限限制等等,一一的百度解决了,最后又出现了 HTTP 错误 502.2 - Bad Gateway Th ...

  2. <每日一题>算法题:集合求并集并排序

    题目描述 给你两个集合,要求{A} + {B}. 注:同一个集合中不会有两个相同的元素. 输入描述: 每组输入数据分为三行,第一行有两个数字n,m(0 ≤ n,m ≤ 10000),分别表示集合A和集 ...

  3. Luogu P2827 蚯蚓(模拟)

    P2827 蚯蚓 题意 题目描述 本题中,我们将用符号\(\lfloor c\rfloor\)表示对\(c\)向下取整,例如:\(\lfloor 3.0\rfloor =\lfloor 3.1\rfl ...

  4. 乌云精华漏洞整合(epub)

    还是7月份的 链接: http://pan.baidu.com/s/1kUGIOez 密码: gfqp

  5. 自定义UICollectionViewLayout(适用于多个section)

    一.自定义layout主要方法 重写系统的- (void)prepareLayout  方法: 其实就是计算每个cell的frame和其它相关属性. 二.在网上看了好多自定义的layout 但是没有多 ...

  6. day 36 MySQL的库、表的详细操作

    MySQL的库.表的详细操作   MySQL数据库 本节目录 一 库操作 二 表操作 三 行操作 一 库操作 1.创建数据库 1.1 语法 CREATE DATABASE 数据库名 charset u ...

  7. 解决编译GCC内存不足的错误

    近期在使用阿里和腾讯的云服务器,由于只是测试用所以只租用了廉价512的内存,在编译gcc时遇到错误,表面上看只是编译错误,并且原因不明,纠结了几次之后猜测应该是由于系统资源不足导致的,所以尝试增加系统 ...

  8. 【DM642学习笔记一】关于Can't Initialize Target CPU的一种解决方法 : Error 0x80000240

    花了几天时间,终于可以顺利进入ccs软件开始学习了! 我使用的是瑞泰公司的ICETEK-DM642-IDK-M图像处理系统(ICETEK5100USB仿真器,仿真芯片为DM642).使用ccs2.21 ...

  9. day71test

    目录 练习: settings.py views.py: exception.py urls.py 练习: 视图类渲染,解析, 异常配置: 作业: 1..简单过过请求模块的源码流程,建立一个视图类,完 ...

  10. Leetcode942. DI String Match增减字符串

    给定只含 "I"(增大)或 "D"(减小)的字符串 S ,令 N = S.length. 返回 [0, 1, ..., N] 的任意排列 A 使得对于所有 i ...