• hdu 2054 A == B ?


    #include<stdio.h>
    #include<string>
    #include<iostream>
    using namespace std;
    string s1,s2;
    int main()
    {
        int i,j;
        while(cin>>s1>>s2)
        {
            int sub=s1.size()-s2.size();
            if(sub>0)
            {
                for(j=0;j<s2.size();j++)
                if(s2[j]=='.')break;
                if(j==s2.size())
                {
                    s2.push_back('.');
                    while(s2.size()<s1.size())
                    s2.push_back('0');
                }
                else
                {
                    while(s2.size()<s1.size())
                    s2.push_back('0');
                }
            }
            else if(sub<0)
            {
                for(j=0;j<s1.size();j++)
                if(s1[j]=='.')break;
                if(j==s1.size())
                {
                    s1.push_back('.');
                    while(s1.size()<s2.size())
                    s1.push_back('0');
                }
                else
                {
                    while(s1.size()<s2.size())
                    s1.push_back('0');
                }
            }
            //cout<<s1<<" "<<s2<<endl;
            for(i=0,j=0;i<s1.size(),j<s2.size();i++,j++)
            {
                if(s1[i]!=s2[j])break;
            }
            if(i==s1.size())printf("YES\n");
            else printf("NO\n");
            s1.clear();
            s2.clear();
        }
        return 0;
    }

    题解:

      字符串s1,s2,相比较,个数小的后面补0(题意明确说明为数字,不会前导0)

      关键在于如何补0(针对需要补0 的字符串):

              1.若出现过小数点,则直接后补0;

              2,否则需补小数点‘ . ’ 后,再补齐0.

  • 相关阅读:
    bzoj 1051: [HAOI2006]受欢迎的牛
    bzoj 1192: [HNOI2006]鬼谷子的钱袋
    一些动规水题
    USACO 2014 Open Silver Fairphoto
    USACO 2013 Nov Silver Pogo-Cow
    09day1
    09day2
    08day2
    08day1
    07day2
  • 原文地址:https://www.cnblogs.com/XDJjy/p/3130550.html
Copyright © 2020-2023  润新知