zoukankan      html  css  js  c++  java
  • PAT A1060_Are They Equel

    AC代码:

    #include <iostream>
    #include <cstdio>
    #include <string>
    using namespace std;
    int n;
    
    string hanshu(string s,int& e)
    {
        while(s.size()>0 && s[0]=='0')     //清除前置0 
            s.erase(s.begin());
        
        if(s[0]=='.')
        {
            s.erase(s.begin());
            while(s[0]=='0' && s.size()>0)
            {
                e--;
                s.erase(s.begin());
            }
        }
        else
        {
            int k=0;
            while(s[k]!='.' && k<s.length())
            {
                e++;
                k++;
            }
            if(k<s.size())     //找到了小数点 
            {
                s.erase(s.begin()+k);
            }
        }
        
        if(s.size() == 0)
            e=0;
        
        int len=s.size();
        string s3="0";
        if(len>=n)
            s.erase(s.begin()+n,s.end());
        else
        {
            while(n-len)
            {
                s.insert(len,s3);
                len++;
            }
        }
        
        return s;
    }
    
    
    int main(void)
    {
        string s1,s2,ss1,ss2;
        int e1=0,e2=0;;
        cin>>n>>s1>>s2;
        
        ss1 = hanshu(s1,e1);
        ss2 = hanshu(s2,e2);
        
        if(ss1==ss2 && e1==e2)
            cout<<"YES 0."<<ss1<<"*10^"<<e1<<endl;
    //        printf("YES 0.%s*10^%d
    ",ss1.c_str(),e1);
        else
            cout<<"NO 0."<<ss1<<"*10^"<<e1<<" 0."<<ss2<<"*10^"<<e2<<endl;
    //        printf("NO 0.%s*10^%d 0.%s*10^%d
    ",ss1.c_str(),e1,ss2.c_str(),e2);
        
        return 0;
    }
  • 相关阅读:
    Remove Linked List Elements
    Count Primes
    Isomorphic Strings
    Read N Characters Given Read4 II
    Word Ladder II Graph
    Word Ladder
    Binary Tree Right Side View
    House Robber
    Find non-overlap jobs with max cost
    Find Peak Element
  • 原文地址:https://www.cnblogs.com/phaLQ/p/10448085.html
Copyright © 2011-2022 走看看