题意:

输入一个正整数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. 传奇HERO引擎给装备加套装属性技巧

    装备加套装在复古的版本里比较少,但在1.76极品,轻变传奇,微变传奇和迷失版本里面用得比较多,每个引擎的方法相差不多,但也有一些小区别,今天给大家讲解下HERO引擎加套装的技巧. 第一步:我们打开M2 ...

  2. 【网易官方】极客战记(codecombat)攻略-地牢-橱柜里的骷髅

    关卡连接: https://codecombat.163.com/play/level/cupboards-of-kithgard 谁知道什么样的恐怖事情潜伏在 Kithgard 的橱柜里? 简介: ...

  3. 计算几何-Ang-Rad-Vector

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 旋转,跳跃,梦境 ...

  4. 服务器安装mysql后配置远程访问权限

    #登录mysql mysql -uroot -p: use mysql: #所有ip能访问 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED B ...

  5. 1.1 Eclipse下载安装(+java环境)

    可直接上官网下载:http://www.eclipse.org/downloads/ 直接下载地址:http://www.eclipse.org/downloads/download.php?file ...

  6. Java进阶学习(5)之设计原则(上)

    设计原则 城堡游戏 扩展 字符串被分割 String line = in.nextLine(); String[] words = line.split(" "); 消除代码复制 ...

  7. 微信个人支付接口---YunGouOS 1.1.3 版本发布,新增个人微信/支付宝收款接口

    软件接口  https://www.oschina.net/news/113305/yungouos-1-1-3-released 文档说明  https://www.oschina.net/p/Yu ...

  8. Ansible - 配置文件

    概述 再水一发 ref Ansible Configuration Settings 1. 查看 概述 查看 配置文件 的默认位置 命令 > ansible --version 结果 confi ...

  9. Go_channel

    通道可以被认为是Goroutines通信的管道.类似于管道中的水从一端到另一端的流动,数据可以从一端发送到另一端,通过通道接收. 在前面讲Go语言的并发时候,我们就说过,当多个Goroutine想实现 ...

  10. SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (gb2312_chinese_ci,COERCIBLE) for operation '='

    在操作MySQL数据库时,报“ error code [1267]; Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_gen ...