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后台运行java的jar包后台运行java -jar 命令

    为什么java -jar 的命令终端的窗口关闭就停止运行了??tomcat中war的就不会? 关闭终端的窗口相当于ctrl+c的命令,关闭了窗口就相当于停止了java -jar这个进程,即ctrl+c ...

  2. 豌豆荚Redis集群方案:Codis

    Codis简介 Codis是一个分布式Redis解决方案,对于上层的应用来说,连接到CodisProxy和连接原生的RedisServer没有明显的区别(不支持的命令列表),上层应用可以像使用单机的R ...

  3. <day001>存储到Mysql、mongoDB数据库+简单的Ajax请求+os模块+进程池+MD5

    任务1:记住如何存储到Mysql.mongoDB数据库 ''' 存储到Mysql ''' import pymysql.cursors class QuotePipeline(object): def ...

  4. java笔试之字符逆序(二)

    与字符逆序(一)不同,句子逆序,单词顺序.例如:I am a student 输出为student a am I. 想法:先字符串句子逆序,然后针对每个单词再逆序一遍. package test; i ...

  5. iOS逆向系列-Mach-O文件

    概述 Mach-O是Mach object的缩写,是Mac\iOS上用于存储程序.库的标准格式. 常见的Mach-O文件 属于Mach-O格式的文件类型有. 可以在xnu源码中,查看到Mach-O格式 ...

  6. iOS开发系列-GCD

    概述 GCD是苹果公司为多核的并行运算提出的解决方案.全称是Grand Central Dospatch.纯C语言,提供了非常多强大的函数. GCD自动管理线程的声明周期(创建线程.调度任务.销毁线程 ...

  7. mybatis 查询sql时foreach使用法

    找到俩个例子摘下来 sql查询用户in传list参数 <select id="getEmpsByConditionForeach" resultType="com. ...

  8. Android开发 WebView的详解

    前言 WebView 是Android显示html内容的主要方式,当然TextView也可以加载html内容.但是WebView除了功能更加强大,最重要的是还能调用Html里的JavaScript语言 ...

  9. 廖雪峰Java15JDBC编程-2SQL入门-1SQL介绍

    1.SQL:结构化查询语言 Structured Query Language 针对关系数据库设计 各种数据库基本一致 允许用户通过SQL查询数据而不关心数据库底层存储结构 1.1 SQL使用: 可以 ...

  10. 廖雪峰Java11多线程编程-3高级concurrent包-9Fork_Join

    线程池可以高效执行大量小任务: Fork/Join线程池可以执行一种特殊的任务: 把一个大任务拆成多个小任务并行执行 Fork/Join是在JDK 1.7引入的 示例:计算一个大数组的和 Fork/J ...