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> ...
随机推荐
- MFC利用ADO建立access数据源 ---包括访问带access密码与不带access密码两种方式)
void CDlg_login::OnButton1() { CString c_user,c_password;m_user1.GetWindowText(c_user);m_password1.G ...
- 100个精选zencart扩展插件
100个精选zencart扩展插件 特别推荐 1. 数据库备份 2. 产品横向布局. 3. 邮件订阅Newsletter Subscribe. 4. google 翻译google_translate ...
- hdu_2243_考研路茫茫——单词情结(AC自动机+矩阵)
题目链接:hdu_2243_考研路茫茫——单词情结 题意: 让你求包含这些模式串并且长度不小于L的单词种类 题解: 这题是poj2788的升级版,没做过的强烈建议先做那题. 我们用poj2778的方法 ...
- 矩阵快速幂AC代码HDU 2035
#include <iostream> using namespace std;const int MOD = 1000;//像这样的一个常量就应该专门定义一下 int PowMod(in ...
- LeetCode OJ 337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this a ...
- javascript克隆一个对象
/* * 克隆一个对象 */ com.ty.repairtech.JsonOperation.clone = function(obj) { // Handle the 3 simple types, ...
- reflow和repaint
Web页面运行在各种各样的浏览器当中,浏览器载入.渲染页面的速度直接影响着用户体验 简单地说,页面渲染就是浏览器将html代码根据CSS定义的规则显示在浏览器窗口中的这个过程.先来大致了解一下浏览器都 ...
- WdatePicker默认日期为当天
不说废话,直接上代码: <input id="d4311" class="Wdate" onfocus="WdatePicker({maxDat ...
- EL表达式处理字符串 是否 包含 某字符串 截取 拆分...............
EL表达式处理字符串 是否 包含 某字符串 截取 拆分............... JSP页面页头添加<%@ taglib uri="/WEB-INF/taglib/c.tld&qu ...
- iOS 判断数组不为空
if (array != nil && ![array isKindOfClass:[NSNull class]] && array.count != 0)