题意:

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

trick:

测试点3含有有效数字在小数点以后的数据,此时指数应该是小数点位置减有效数字位置再加上1。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string a,b;
int ans_a[],ans_b[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
cin>>a>>b;
int cnt=;
int posa=a.size();
int posb=b.size();
int staa=a.size();
int stab=b.size();
for(int i=;i<a.size();++i)if(a[i]=='.'){
posa=i;
break;
}
for(int i=;i<b.size();++i)if(b[i]=='.'){
posb=i;
break;
}
for(int i=;i<a.size();++i)if(a[i]!=''&&a[i]!='.'){
staa=i;
break;
}
for(int i=;i<b.size();++i)if(b[i]!=''&&b[i]!='.'){
stab=i;
break;
}
for(int i=staa;i<a.size();++i){
if(a[i]=='.')
continue;
if(cnt<n)
ans_a[++cnt]=a[i]-'';
}
for(int i=cnt+;i<=n;++i)
ans_a[i]=;
int tot=;
for(int i=stab;i<b.size();++i){
if(b[i]=='.')
continue;
if(tot<n)
ans_b[++tot]=b[i]-'';
}
for(int i=tot+;i<=n;++i)
ans_b[i]=;
int flag=;
for(int i=;i<=n;++i)if(ans_a[i]!=ans_b[i])
flag=;
if(!flag&&posa-staa==posb-stab||staa==a.size()&&stab==b.size())
cout<<"YES ";
else
cout<<"NO ";
cout<<"0.";
for(int i=;i<=n;++i)
cout<<ans_a[i];
int ans=;
if(posa-staa<)
ans=posa-staa+;
else
ans=posa-staa;
if(staa==a.size())
ans=;
cout<<"*10^"<<ans;
if((flag||posa-staa!=posb-stab)&&(staa!=a.size()||stab!=b.size())){
cout<<" 0.";
for(int i=;i<=n;++i)
cout<<ans_b[i];
int anss=;
if(posa-staa<)
anss=posb-stab+;
else
anss=posb-stab;
if(stab==b.size())
anss=;
cout<<"*10^"<<anss;
}
return ;
}

【PAT甲级】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 分)   If a machine can save only 3 significant digits, the float numbers 1230 ...

  3. 1060 Are They Equal (25分)

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

  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. PAT 甲级 1060 Are They Equal

    1060. Are They Equal (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue If a ma ...

  6. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  7. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  8. PAT甲级——1130 Infix Expression (25 分)

    1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...

  9. PAT 甲级 1074 Reversing Linked List (25 分)(链表部分逆置,结合使用双端队列和栈,其实使用vector更简单呐)

    1074 Reversing Linked List (25 分)   Given a constant K and a singly linked list L, you are supposed ...

  10. PAT 甲级 1086 Tree Traversals Again (25分)(先序中序链表建树,求后序)***重点复习

    1086 Tree Traversals Again (25分)   An inorder binary tree traversal can be implemented in a non-recu ...

随机推荐

  1. Web 安全工具篇:Burp Suite 使用指南

    真的是一点都不过分,了解详情请继续往下读. Burp Suite 介绍 Burp Suite 是用于攻击 web 应用程序的集成平台.它包含了许多工具,并为这些工具设计了许多接口,以促进加快攻击应用程 ...

  2. Linux上后台运行node和springboot服务

    环境:Ubuntu18.04 阿里云云服务器 尝试全局安装forever和pm2均失败,最后以linux自带的nohub启动,以前同样用nohub启动springboot 命令: nohup npm ...

  3. codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)

    题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...

  4. springboot06(静态资源映射)

    xxxxAutoConfiguration xxxxproperties 对静态资源的映射规则 webjars @ConfigurationProperties(prefix = "spri ...

  5. Gym-TORCS安装

    系统为Ubuntu16.04来安装Gym-TORCS 安装pip: sudo apt-get install python-pip sudo pip install --upgrade pip 安装p ...

  6. RestTemplate-记录

    org.springframework.web.client.RestTemplate 1.从使用功能上看,是一种简化请求响应的工具类,从发送请求,到对返回的结果进行json解析.格式不对会有异常.

  7. Nexus坑人系列-interface Unknown state L3 Not Ready

    这个情况也容易出现在新使用设备的时候,当设备上没有L3接口模块的时候,这个问题就出现了. 接下来,尤其是如果我们需要运行VPC(并且如果正在运行N5K,N7K等!),则需要在交换机上配置第3层接口. ...

  8. C语言 time、rand、srand

    C语言 time.rand.srand #include <time.h> time_t time(time_t *t); 功能:获取当前系统时间 参数:常设置为NULL 返回值:当前系统 ...

  9. laravel Excel导入导出

    1.简介 Laravel Excel 在 Laravel 5 中集成 PHPOffice 套件中的 PHPExcel,从而方便我们以优雅的.富有表现力的代码实现Excel/CSV文件的导入和导出. 该 ...

  10. tomcat安装成功以后进行测试步骤:

    tomcat安装成功以后进行测试步骤: 编写测试页面: 进入Tomcat安装对应路径: E:\Tomcat\apache-tomcat-8.5.45\webapps\ROOT 创建:test.jsp ...