PAT (Advanced Level) 1060. Are They Equal (25)
模拟题。坑点较多。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<stack>
#include<vector>
using namespace std; int n;
string s,t;
struct X
{
string f;
int idx;
} ans[]; string change(string a)
{
string res;
if(a.length()-<n)
{
for(int i=a.length()-;i<n;i++) a=a+"";
res=a;
} else if(a.length()->n)
{
res="0.";
for(int i=;i<n+;i++) res=res+a[i];
}
else res=a;
return res;
} string qu(string a)
{
string res;
if(a.length()==&&a[]=='') return a; int pos=-;
for(int i=; i<a.length(); i++) if(a[i]=='.') pos=i; if(pos==-)
{
for(int i=; i<a.length(); i++)
{
if(a[i]=='') continue;
else
{
for(int j=i; j<a.length(); j++) res=res+a[j];
break;
}
}
}
else
{
for(int i=; i<pos-; i++)
{
if(a[i]=='') continue;
else
{
for(int j=i; j<pos-; j++) res=res+a[j];
break;
}
}
for(int i=pos-; i<a.length(); i++) res=res+a[i];
} if(res.length()==) res="";
return res;
} void R(int a)
{
bool ling=;
for(int i=; i<ans[a].f.length(); i++)
{
if(ans[a].f[i]=='.') continue;
if(ans[a].f[i]!='') ling=;
} if(ling) ans[a].idx=;
} void PUT(int a)
{
cout<<ans[a].f<<"*10^"<<ans[a].idx;
} int main()
{
scanf("%d",&n);
cin>>s>>t; s=qu(s);
t=qu(t); if(s[]==''&&s[]=='.')
{
int num=;
for(int i=; i<s.length(); i++)
{
if(s[i]=='') num++;
else
{
ans[].idx=-num;
ans[].f="0.";
for(int j=i; j<s.length(); j++) ans[].f=ans[].f+s[j];
break;
}
}
if(ans[].f.length()==)
{
ans[].f="0.0";
ans[].idx=;
}
} else
{
int pos=-;
for(int i=; i<s.length(); i++) if(s[i]=='.') pos=i;
if(pos!=-)
{
ans[].f="0.";
for(int i=; i<s.length(); i++) if(s[i]!='.') ans[].f=ans[].f+s[i];
ans[].idx=pos;
}
else
{
ans[].f="0."+s;
ans[].idx=s.length();
}
} ans[].f=change(ans[].f); if(t[]==''&&t[]=='.')
{
int num=;
for(int i=; i<t.length(); i++)
{
if(t[i]=='') num++;
else
{
ans[].idx=-num;
ans[].f="0.";
for(int j=i; j<t.length(); j++) ans[].f=ans[].f+t[j];
break;
}
}
if(ans[].f.length()==)
{
ans[].f="0.0";
ans[].idx=;
}
}
else
{
int pos=-;
for(int i=; i<t.length(); i++) if(t[i]=='.') pos=i;
if(pos!=-)
{
ans[].f="0.";
for(int i=; i<t.length(); i++) if(t[i]!='.') ans[].f=ans[].f+t[i];
ans[].idx=pos;
}
else
{
ans[].f="0."+t;
ans[].idx=t.length();
}
} ans[].f=change(ans[].f); R(); R(); if(ans[].f==ans[].f&&ans[].idx==ans[].idx)
{
printf("YES ");
PUT();
} else
{
printf("NO ");
PUT();
cout<<" ";
PUT();
cout<<endl;
} return ;
}
PAT (Advanced Level) 1060. Are They Equal (25)的更多相关文章
- 【PAT甲级】1060 Are They Equal (25 分)(需注意细节的模拟)
题意: 输入一个正整数N(<=100),接着输入两个浮点数(可能包含前导零,对于PAT已经习惯以string输入了,这点未知),在保留N位有效数字的同时判断两个数是否相等,并以科学计数法输出. ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1110. Complete Binary Tree (25)
判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...
- PAT (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT (Advanced Level) 1074. Reversing Linked List (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1062. Talent and Virtue (25)
简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...
- PAT (Advanced Level) 1056. Mice and Rice (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- PAT (Advanced Level) 1053. Path of Equal Weight (30)
简单DFS #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1052. Linked List Sorting (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- Sikuli:创新的图形化编程技术
Sikuli是一种使用截图进行UI自动化测试的技术.Sikuli包括sikul脚本,基于Jython的API以及sikuli IDE.Sikuli可以实现任何你可以在显示器上看到ui对象的自动化,你可 ...
- 编写一个闹钟和定时关机工具(MFC VS2010)
这个小工具在自己生活当中能用到,运行软件以后,会显示当前的系统时间,然后你可以设定时间,再选择是定时响铃还是关机.截图如下: 前言:本程序采用visual studio 2010 ,对话框类型的应用程 ...
- php mysql数据库 分页与搜索
<?php/** * Created by coder meng. * User: coder meng * Date: 2016/8/29 10:27 */header("Conte ...
- @Value 注解获取properties值
转自:使用Spring 3的@value简化配置文件的读取 Spring 3支持@value注解的方式获取properties文件中的配置值,大简化了读取配置文件的代码. 1.在application ...
- /etc/fstab 文件解释
/etc/fstab 文件解释 文件fstab包含了你的电脑上的存储设备及其文件系统的信息.它是决定一个硬盘(分区)被怎样使用或者说整合到整个系统中的唯一文件. 这个文件的全路径是/etc/fstab ...
- 当list做gridview的数据源时,可以用泛型来对list进行排序
当list做gridview的数据源时,可以用泛型来对list进行排序 ,代码如下 var temps = from t in list orderby t.paymentAmount descend ...
- C: Run a System Command and Get Output? 在C程序中调用工具,并且得到结果。
现在在做一个WIFI API相关的库,这样就可以让其他的人管理WIFI. 在调用API的时候要回复SHELL打印的信息,比如说搜索热点,而且不在SHELL中打印出来.然后把信息返回给调用API的程序. ...
- C#中使用正则表达式提取超链接地址的集中方法
一般在做爬虫或者CMS的时候经常需要提取 href链接或者是src地址.此时可以使用正则表达式轻松完成. Regex reg = new Regex(@"(?is)<a[^>]* ...
- JavaScript的第一次小结
一. JavaScript是一种的脚本语言:特点是:具有解释性,基于对象,事件驱动,安全性和跨平台等特点 对于这几种特点有必要说明一下 解释性:就是JavaScripte本身就是一种解释性语言 基于对 ...
- html 背景透明文字不透明
.alpha{ width: 100px; height: 100px; color: #fff; background: rgba(0, 0, 0, .3); filter: progid:DXIm ...