pat1060题

算法思路:
只需要仔细分析各种情况,分好类别即可。

#include <iostream>
#include <vector>
#include <math.h>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
int n;
string fun(string s,int &k)
{

    string ans;

    while(s.size()>0&&s[0]=='0'){
        s.erase(s.begin());
    }

    int i=0;
    if(s[0]=='.'){

        s.erase(s.begin());
        while(s.length()>0&&s[0]=='0'){
            k--;
            s.erase(s.begin());

        }
        i=0;
        if(s.length()==0) k=0;
        while(ans.size()<n){
            if(i<s.size())
            ans=ans+s[i++];
            else{
                ans+='0';
            }
        }
        return ans;

    }else{
            i=0;
            while(i<s.length()&&s[i]!='.')
            {
                i++;

                k++;

                if(s[i]=='.'&&i<s.length()){
                    s.erase(i);//天哪,我开始写的是s.erase(s[i]),,噗
                    break;
                }

            }
        i=0;
        if(s.length()==0) k=0;
        while(ans.length()<n){
            if(i<s.size())
            ans=ans+s[i++];
            else{
                ans+='0';
            }

        }
        return ans;
    }


}


int main()
{
      string s1,s2,s3,s4;

      cin >> n >>s1>>s2;

      int e1=0,e2=0;
      s3=fun(s1,e1);
      s4=fun(s2,e2);
        if(s3==s4&&e1==e2){
            printf("YES ");
            cout<<"0."<<s3<<"*10^"<<e1;

        }
        else{
            printf("NO ");
            cout<<"0."<<s3<<"*10^"<<e1<<" 0."<<s4<<"*10^"<<e2;

        }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值