1060 Are They Equal (25 分)
 

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×10​5​​ 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 10​100​​, 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<bits/stdc++.h>
using namespace std; int n;
string a,b; const int maxn=; struct bign{
string d;
int cnt;
}; bign change(string str,int k){ bool flag=false; bign ans; int len=(int)str.size(); int i=; while(i<len&&str[i]=='')
{
i++;
} int pos1=-,pos2=-; while(i<len){
if(str[i]=='.')
pos2=i;
else if(str[i]!=''||flag){
ans.d+=str[i];
if(pos1==-)
pos1=i; flag=true; } i++;
} if(i>=len&&pos2==-)
pos2=len; if(pos2>pos1)
ans.cnt=pos2-pos1;
else
ans.cnt=pos2-pos1+; //cout<<pos1<<endl<<pos2<<endl; int anslen=(int)ans.d.size(); if(anslen>=k)
ans.d=ans.d.substr(,k);
else{
int h=k-anslen;
while(h--)
ans.d+='';
} if(flag==false)
ans.cnt=; return ans; } bool judge(bign a,bign b){
if(a.d==b.d&&a.cnt==b.cnt)
return true;
else
return false;
} void print(bign a){
cout<<" 0."<<a.d<<"*10^"<<a.cnt;
} int main(){
cin>>n;
cin>>a>>b; bign ansa,ansb; ansa=change(a,n);
ansb=change(b,n); bool flag = judge(ansa,ansb); if(flag){
cout<<"YES";
print(ansa);
} else{
cout<<"NO";
print(ansa);
print(ansb); } return ; }

1060 Are They Equal (25 分)的更多相关文章

  1. 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 ...

  2. 1060 Are They Equal (25分)

    1060 Are They Equal (25分) 题目 思路 定义结构体 struct fraction{ string f; int index; } 把输入的两个数先都转换为科学计数法,统一标准 ...

  3. 【PAT甲级】1060 Are They Equal (25 分)(需注意细节的模拟)

    题意: 输入一个正整数N(<=100),接着输入两个浮点数(可能包含前导零,对于PAT已经习惯以string输入了,这点未知),在保留N位有效数字的同时判断两个数是否相等,并以科学计数法输出. ...

  4. 【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 ...

  5. 1060. Are They Equal (25)

    题目如下: If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are consi ...

  6. 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 ...

  7. PAT (Advanced Level) 1060. Are They Equal (25)

    模拟题.坑点较多. #include<iostream> #include<cstring> #include<cmath> #include<algorit ...

  8. PAT甲题题解-1060. Are They Equal (25)-字符串处理(科学计数法)

    又是一道字符串处理的题目... 题意:给出两个浮点数,询问它们保留n位小数的科学计数法(0.xxx*10^x)是否相等.根据是和否输出相应答案. 思路:先分别将两个浮点数转换成相应的科学计数法的格式1 ...

  9. A1060 Are They Equal (25 分)

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

随机推荐

  1. java com.db4o 类

    <!--juan_zhai--> <dependency> <groupId>com.db4o</groupId> <artifactId> ...

  2. ASP.NET Core学习——6

    依赖注入DI ASP.NET Core的底层设计支持和使用依赖注入.ASP.NET Core应用程序可以利用内置的框架服务将它们注入到启动类的方法中,并且应用程序服务能够配置注入. 1.什么是依赖注入 ...

  3. 25. 服务器性能监控之nmon工具介绍

    nmon介绍: nmon是一个简单的性能监测工具,可以监测CPU.内存.网络等的使用情况. 步骤: 1.下载nmon(根据你的操作系统下载),地址 2.nmon文件部署到服务器中 3.启动nmon(注 ...

  4. RTTI RAII

    RTTI(Run Time Type Identification)即通过运行时类型识别,程序能够使用基类的指针或引用来检查着这些指针或引用所指的对象的实际派生类型. RTTI提供了以下两个非常有用的 ...

  5. WPF 依赖附加属性

    附加属性的本质是一个依赖属性,与普通的依赖属性区别: 1:注册方法名不一样,如 DependencyProperty.RegisterAttached 2:没有普通的属性包装器,而是通过get和set ...

  6. yum常见问题

    --> Finished Dependency Resolution Error: Multilib version problems found. This often means that ...

  7. 深入JAVA虚拟机笔记-垃圾收集器与内存分配策略

    第三章:垃圾收集器与内存分配 问题:1.哪些内存需要回收 2.什么时候回收 3.怎么回收 回收方法区:

  8. 博客中引入了gitment评论系统

    官方github地址:https://github.com/imsun/gitment 官方中文说明地址:https://imsun.net/posts/gitment-introduction/ 官 ...

  9. 五分钟学GIS | 快速生成地图瓦片秘籍

    什么是地图瓦片? 地图瓦片是包含了一系列比例尺.一定地图范围内的地图切片文件.地图瓦片按照金字塔结构组织,每张瓦片都可通过级别.行列号唯一标记.在平移.缩放地图时,浏览器根据金字塔规则,计算出所需的瓦 ...

  10. 【JS学习】慕课网7-23编程练习 有关字符串数组

    要求:1.显示打印的日期. 格式为类似“2014年03月21日 星期三” 的当前的时间.2.计算出该班级的平均分(保留整数).同学成绩数据如下:"小明:87; 小花:81; 小红:97; 小 ...