1060 Are They Equal (25 分)
 

If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×10​5​​ with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are supposed to tell if they are treated equal in that machine.

Input Specification:

Each input file contains one test case which gives three numbers N, A and B, where N (<100) is the number of significant digits, and A and B are the two float numbers to be compared. Each float number is non-negative, no greater than 10​100​​, and that its total digit number is less than 100.

Output Specification:

For each test case, print in a line YES if the two numbers are treated equal, and then the number in the standard form 0.d[1]...d[N]*10^k (d[1]>0 unless the number is 0); or NO if they are not treated equal, and then the two numbers in their standard form. All the terms must be separated by a space, with no extra space at the end of a line.

Note: Simple chopping is assumed without rounding.

Sample Input 1:

3 12300 12358.9

Sample Output 1:

YES 0.123*10^5

Sample Input 2:

3 120 128

Sample Output 2:

NO 0.120*10^3 0.128*10^3

#include<bits/stdc++.h>
using namespace std; int n;
string a,b; const int maxn=; struct bign{
string d;
int cnt;
}; bign change(string str,int k){ bool flag=false; bign ans; int len=(int)str.size(); int i=; while(i<len&&str[i]=='')
{
i++;
} int pos1=-,pos2=-; while(i<len){
if(str[i]=='.')
pos2=i;
else if(str[i]!=''||flag){
ans.d+=str[i];
if(pos1==-)
pos1=i; flag=true; } i++;
} if(i>=len&&pos2==-)
pos2=len; if(pos2>pos1)
ans.cnt=pos2-pos1;
else
ans.cnt=pos2-pos1+; //cout<<pos1<<endl<<pos2<<endl; int anslen=(int)ans.d.size(); if(anslen>=k)
ans.d=ans.d.substr(,k);
else{
int h=k-anslen;
while(h--)
ans.d+='';
} if(flag==false)
ans.cnt=; return ans; } bool judge(bign a,bign b){
if(a.d==b.d&&a.cnt==b.cnt)
return true;
else
return false;
} void print(bign a){
cout<<" 0."<<a.d<<"*10^"<<a.cnt;
} int main(){
cin>>n;
cin>>a>>b; bign ansa,ansb; ansa=change(a,n);
ansb=change(b,n); bool flag = judge(ansa,ansb); if(flag){
cout<<"YES";
print(ansa);
} else{
cout<<"NO";
print(ansa);
print(ansb); } return ; }

最新文章

  1. 【补充】Gitlab 部署 CI 持续集成
  2. Python anaconda links to GOMP_4.0 and throws error
  3. 数据结构算法C语言实现(八)--- 3.2栈的应用举例:迷宫求解与表达式求值
  4. quick lua 3.3常用方法和学习技巧之transition.lua
  5. 登录界面 beta版
  6. hbase与Hadoop
  7. IDA 使用技巧
  8. wave文件(*.wav)格式、PCM数据格式, goldwave 可以播放pcm raw audio
  9. 杭州(含嘉兴,绍兴,金华,湖州,义乌)Uber优步司机奖励政策(1月25日~1月31日)
  10. AES加密时抛出java.security.InvalidKeyException:&#160;Illegal&#160;key&#160;size&#160;or&#160;def
  11. C# 中获取时区列表
  12. vue-resource promise兼容性问题
  13. Another option for file sharing(转)
  14. [国嵌笔记][006][Linux文本编辑器]
  15. HTTP与私有二进制协议之间的区别
  16. web.xml中的ContextLoaderListener和DispatcherServlet区别
  17. MySQL 5.6容器使用自定义配置文件的权限问题
  18. pom.xml中添加远程仓库
  19. 性能优化系列七:SQL优化
  20. python seek()方法报错:“io.UnsupportedOperation: can&#39;t do nonzero cur-relative seeks”

热门文章

  1. HTML5: HTML5 Video(视频)
  2. Openstack组件部署 — 将一个自定义 Service 添加到 Keystone
  3. excel数据生成sql insert语句
  4. linux基础--目录介绍
  5. python学习笔记:操作数据库
  6. Java内部类类型
  7. 获取项目根目录(非tomact)
  8. WEB前端资源集
  9. [轉]User namespaces – available to play!
  10. How to easily Detect Objects with Deep Learning on Raspberry Pi