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. Webx.0-Web2.0:Web2.0

    ylbtech-Webx.0-Web2.0:Web2.0 Web2.0 是相对于Web1.0 的新的时代.指的是一个利用Web的平台,由用户主导而生成的内容互联网产品模式,为了区别传统由网站雇员主导生 ...

  2. linux shell unzip multiple zip files

    find . -name "*.result.zip" | xargs -n 1 unzip - -P password -d ../ext_logs

  3. git 关于commit命令的修改

    1 修改最后一次提交的信息 git commit --amend 2 对于历史提交 git rebase -i HEAD~5 没毛病,

  4. C语言各种进制输出

    #include<stdio.h> int main() { ; float f = 12.0; printf("十进制输出:%d\n", number); print ...

  5. 【记录】Windows host配置域名

    程序员开发中可能会需要域名访问程序,说白了就是修改hosts文件,过程如下: 1:找到本机hosts文件路径一般位置在: C:\Windows\System32\drivers\etc 2:右键编辑h ...

  6. 【JS学习】慕课网8-17编程练习 网页的返回与跳转

    编程练习 制作一个跳转提示页面: 要求: 1. 如果打开该页面后,如果不做任何操作则5秒后自动跳转到一个新的地址,如慕课网主页. 2. 如果点击“返回”按钮则返回前一个页面. 代码如下: 需要注意的是 ...

  7. 欧拉路径 && 欧拉回路

  8. 笔记66 Spring Boot快速入门(六)

    SpringBoot中使用Mybatis 一.注解方式 1.创建映射文件CategoryMapper.java 使用注解@Mapper 表示这是一个Mybatis Mapper接口.使用@Select ...

  9. 62. File类常用方法

    为了怕混淆,先说明一些下面要出现的名词意思:例如:D:\\新建文件夹 (2)\\a.txt 和  D:\\新建文件夹 (2)\\aaaa D:\\新建文件夹 (2)   父路径    a.txt    ...

  10. Delphi 常用API 函数列表

    Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWi ...