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
 #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std; // 0000.0012 0123.34
char str1[], str2[];
int process(char s[], int len){
int i,j, exp;
for(i = ; s[i] != '\0' && s[i] == ''; i++); //去除前导0
if(s[i] != '\0'){
for(j = ; s[j + i] != '\0'; j++)
s[j] = s[j + i];
s[j] = '\0';
}else{
for(int k = ; k < len; k++)
s[k] = '';
s[len] = '\0';
return ;
}
if(s[] == '.'){ //.0012
for(i = ; s[i] != '\0' && s[i] == ''; i++);
if(s[i] == '\0'){
exp = ;
s[] = '';
}else{
exp = i - ;
exp *= -;
for(j = ; s[i + j] != '\0'; j++)
s[j] = s[j + i];
s[j] = '\0';
}
}else{ //123.456
for(i = ; s[i] != '\0' && s[i] != '.'; i++);
if(s[i] == '\0'){
exp = i;
}else{
exp = i;
for(; s[i + ] != '\0'; i++)
s[i] = s[i + ];
s[i] = '\0';
}
}
for(j = ; s[j] != '\0'; j++);
while(j < len){
s[j++] = '';
}
s[len] = '\0';
return exp;
}
int main(){
int N, exp1, exp2;
scanf("%d %s %s", &N, str1, str2);
exp1 = process(str1, N);
exp2 = process(str2, N);
int tag = ;
for(int i = ; str1[i] != '\0'; i++)
if(str1[i] != str2[i]){
tag = ;
break;
}
if(tag == && exp1 == exp2){
printf("YES 0.%s*10^%d", str1, exp1);
}else{
printf("NO 0.%s*10^%d 0.%s*10^%d", str1, exp1, str2, exp2);
}
cin >> N;
return ;
}

总结:

1、题意:将给出的两个数字变成保留指定位小数的科学计数法的数字,之后看其是否相等。

2、主要分为两种数字,大于1和小于1(0.000123, 1234.5678),其次要注意有0000123的情况出现,要先去除前导0.

3、主要要做的就是想办法求出不带小数点的且符合要求的底数。

4、测试样例: 3 0.0 0

输出:YES 0.000*10^0

A1060. Are They Equal的更多相关文章

  1. 【算法笔记】A1060 Are They Equal

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

  2. PAT甲级——A1060 Are They Equal

    If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered ...

  3. A1060 Are They Equal (25 分)

    一.技术总结 cnta.cntb用于记录小数点出现的位置下标,初始化为strlen(字符串)长度. q.p用于记录第一个非0(非小数点)出现的下标,可以用于计算次方和方便统计输出的字符串,考虑到前面可 ...

  4. [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  5. [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等

    Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...

  6. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  7. Equal Sides Of An Array

    参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...

  8. Int,Long比较重使用equal替换==

    首先,==有很多限制,如Integer 类型的值在[-128,127] 期间,Integer 用 “==”是可以的(参考),超过范围则不行,那么使用equal则代替则完全ok public stati ...

  9. 无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS"

    无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS" 之间 2011-0 ...

随机推荐

  1. Salesforce随笔: 将Visualforce Page导出为 Excel/CSV/txt (Display a page in Excel)

    想要实现如题所述功能,可以参照 : Visualforce Developer Guide 第57页中所举的例子,在<apex:page>标签中添加contentType属性. <a ...

  2. Centos7下ELK+Redis日志分析平台的集群环境部署记录

    之前的文档介绍了ELK架构的基础知识,日志集中分析系统的实施方案:- ELK+Redis- ELK+Filebeat - ELK+Filebeat+Redis- ELK+Filebeat+Kafka+ ...

  3. E. Train Hard, Win Easy

    链接 [http://codeforces.com/contest/1043/problem/E] 题意 有n个人,每个人都有做出a,b题的分数,xi,yi,但是有些人是不能组队的,问你每个人和其他能 ...

  4. 《Linux内核分析》第六周笔记 进程的描述和进程的创建

    进程的描述和进程的创建 一.进程的描述 1.进程描述符task_struct数据结构(一) 操作系统的三大功能:进程管理(核心).内存管理.文件系统. 进程控制块PCB——task_struct(进程 ...

  5. C++课程学习建议

    从C到C++,学院都采用了机房授课模式,也在探索更为高效的实践与理论融合的教学方法,对于课程学习来说,仍有以下建议: 1.多看书.看书是理解基本概念的必备手段.也是学习的根本.应将课前预习.课后复习联 ...

  6. 【转】使用screw plus对PHP源码加密

    运行环境 ubuntu 14.04 php 5.6 源码地址 https://github.com/del-xiong/screw-plus http://git.oschina.net/splot/ ...

  7. PHP使用cookie时遇到的坑

    先看这么一段代码 第一次运行该程序的结果如下图: 然后我刷新了一次,运行结果如下图 你如果不细心,一定没发现,第二次运行的last time的值,正是第一次运行时保存的值. 先看代码,如果$_COOK ...

  8. HDU 2029 Palindromes _easy version

    http://acm.hdu.edu.cn/showproblem.php?pid=2029 Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“ ...

  9. Activiti reassign task to another user

    //早先胡乱尝试的其他方法,可能对于以后深入学习Activiti有些用处. //taskService.delegateTask(taskId, receiveUserId); //taskServi ...

  10. CentOS 7 Install Adobe Flash Player

    From Officail Adobe Flash Site don't down (YUM )adobe-release-x86_64-1.0-1.noarch.rpm,but to downloa ...