模拟题。坑点较多。

#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)的更多相关文章

  1. 【PAT甲级】1060 Are They Equal (25 分)(需注意细节的模拟)

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

  2. PAT (Advanced Level) 1113. Integer Set Partition (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  3. PAT (Advanced Level) 1110. Complete Binary Tree (25)

    判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...

  4. PAT (Advanced Level) 1094. The Largest Generation (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  5. PAT (Advanced Level) 1074. Reversing Linked List (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  6. PAT (Advanced Level) 1062. Talent and Virtue (25)

    简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...

  7. PAT (Advanced Level) 1056. Mice and Rice (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  8. PAT (Advanced Level) 1053. Path of Equal Weight (30)

    简单DFS #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  9. PAT (Advanced Level) 1052. Linked List Sorting (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. nefu 196 让气球飞吧

    description 国际大学生程序设计竞赛已经发展成为最具影响力的大学生计算机竞赛,ACM-ICPC以团队的形式代表各学校参赛,每队由3名队员组成,一个队每做出来一个题该队就会获得该题对应颜色的气 ...

  2. @font-face的用法

    几乎所有浏览器(包括最古老的IE6)也支持的网络字体@font-face的用法是: @font-face { font-family: 'MyWebFont'; src: url('webfont.e ...

  3. Xcode6无法用xib得问题解决方法

    1.创建一个新工程,选择singleView application 2.将storyboard和launchscreen删除,选择moveToTrash 3.删除info.plist文件中Main ...

  4. SQL SERVER与C#的数据类型对应表

    序号 类别 SQLServer C Sharp 备注 1 整数 bit Boolean True转换为1False转换为0 2 tinyint Byte C Sharp 数据类型都位于System命名 ...

  5. WEBROOT根目录 <%=request.getContextPath()%>

    WEBROOT根目录 <%=request.getContextPath()%> == ${pageContext.request.contextPath}

  6. PHP运行模式(cgi,fast-cgi,cli, ISAPI ,web模块模式)【转载】

    PHP运行模式有5钟: 1)cgi 通用网关接口(Common Gateway Interface))2)fast-cgi 常驻 (long-live) 型的 CGI3)cli  命令行运行   (C ...

  7. kill -0

    http://unix.stackexchange.com/questions/169898/what-does-kill-0-do 检查有没有权限杀他

  8. Python 入门基础学习

     Python入门学习  我们使用python3.0版本 首选来入门  带你进入Hello World >>> print ("Hello World")Hell ...

  9. Mybatis 一对一,一对多,多对一,多对多的理解

    First (一对一) 首先我来说下一对一的理解,就是一个班主任只属于一个班级,一个班级也只能有一个班主任.好吧这就是对于一对一的理解 怎么来实现呢? 这里我介绍了两种方式: 一种是:使用嵌套结果映射 ...

  10. 32位Intel CPU所含有的寄存器

    4个数据寄存器(EAX.EBX.ECX和EDX)2个变址和指针寄存器(ESI和EDI) 2个指针寄存器(ESP和EBP)6个段寄存器(ES.CS.SS.DS.FS和GS)1个指令指针寄存器(EIP) ...