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> ...
随机推荐
- Table隔行变色的JavaScript代码
<table id="datatable"> <tr> <td>脚本之家</td> </tr> <tr> & ...
- openwrt默认不开启wifi
Openwrt默认不开启wifi,要开启的话, 修改这个文件: openwrt/trunk/package/kernel/mac80211/files/lib/wifi/mac80211.sh. 滚到 ...
- Git合并分支出现的冲突解决
人生不如意之事十有八九,合并分支往往也不是一帆风顺的. 我们准备新的分支newbranch. LV@LV-PC MINGW32 /c/gitskill (master)$ git checkout - ...
- 第3章 Java语言基础----static
1.static只能声明成员变量,不能声明局部变量,如下图所示: 2.如果变量在类中用static中定义过,那么在方法中就可以直接赋值了:如果没有在类中定义,则不能在方法中使用,还得重新定义,如下图所 ...
- ios根据颜色返回图片
+(UIImage*) createImageWithColor:(UIColor*) color { CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); ...
- AOP与动态代理有什么联系
曾遇到“AOP与动态代理有什么联系”的问题,现把个人观点整理如下: 我觉得,动态代理是AOP的主要实现手段之一,AOP是动态代理的一种应用深化 AOP是一种思想,或者是方法论,类似OOP,是OOP的有 ...
- centos主机信任
一.实现原理 使用一种被称为"公私钥"认证的方式来进行ssh登录."公私钥"认证方式简单的解释是: 首先在客户端上创建一对公私钥(公钥文件:~/.ssh/id_ ...
- Java 中的四种引用及垃圾回收策略
Java 中有四种引用:强引用.软引用.弱引用.虚引用: 其主要区别在于垃圾回收时是否进行回收: 1.强引用 使用最普遍的引用.如果一个对象具有强引用,那就 类似于必不可少的生活用品,垃圾回收器绝不会 ...
- Encoding filter 编码过滤器
1.首先编写过滤器,实际上就是继承了filter接口的一个类,实现其中的init doChain 和destroy方法 package com.util; import java.io.IOExc ...
- 扩展方法之ToDictionary()
Person类: public class Person { public int Id { set; get; } public string WorkNo { set; get; } public ...