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. MacBook Pro 快捷键2

    Mac 键盘快捷键 您可以按下组合键来实现通常需要鼠标.触控板或其他输入设备才能完成的操作.   要使用键盘快捷键,请按住一个或多个修饰键,同时按快捷键的最后一个键.例如,要使用快捷键 Command ...

  2. MyEclipse增强代码补全

    MyElipse的默认代码提示功能隐藏了许多细节,需要开发者手动设置,一起来设置吧,让你的myeclpse更强大. 方法 1 打开MyEclipse 6.0.1,然后“window”→“Prefere ...

  3. Java方法覆盖教程

    重新定义来自超类(父类)继承的类中的实例方法称为方法覆盖. 示例 现在来看看,类A和类B的以下声明,覆盖了 print() 方法 : 1 2 3 4 5 6 7 8 9 10 11 public cl ...

  4. python基础【第五篇】

    python第三节 1.整型及布尔值 1.1 进制转换 十进制 ----二进制 二进制 ----十进制 8421方法与普通计算 python中十进制转二进制示例:bin(51)>>> ...

  5. 使用python解析C代码

    我有一个巨大的C文件(~100k行),我需要能够解析.主要是我需要能够从其定义中获取有关每个结构的各个字段的详细信息(如结构中每个字段的字段名称和类型).是否有一个好的(开源,我可以在我的代码中使用) ...

  6. 在命令行中插入TAB键

    参考man bash: quoted-insert (C-q, C-v) Add the next character typed to the line verbatim.  This is how ...

  7. 初探Remoting双向通信(二)

    原 初探Remoting双向通信(二) 2013年06月25日 11:46:24 喜欢特别冷的冬天下着雪 阅读数 2977 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...

  8. 解决HDFS小文件带来的计算问题

    hive优化 一.小文件简述 1.1. HDFS上什么是小文件? HDFS存储文件时的最小单元叫做Block,Hadoop1.x时期Block大小为64MB,Hadoop2.x时期Block大小为12 ...

  9. activiti网关

    activiti中有两种网关:并行网关,排他网关. 排他网关用于任务选择等情况,流程图如下 bpnm代码如下 <?xml version="1.0" encoding=&qu ...

  10. stat - 打印信息节点(inode)内容

    SYNOPSIS(总览) stat filename [filenames ... ] DESCRIPTION(描述) stat 打印出一个信息节点的内容,它们显示为对人可读的格式的stat(2). ...