zoukankan      html  css  js  c++  java
  • hdu2054

    http://acm.hdu.edu.cn/showproblem.php?pid=2054

    很烦的题~~

    View Code
    #include"iostream"
    #include
    "string"
    using namespace std;
    int i,j,L1,L2;
    char a[20000],b[20000];
    int main()
    {
    while(scanf("%s %s",&a,&b)!=EOF)
    {
    if(a[0]=='-'&&b[0]=='-'||a[0]!='-'&&b[0]!='-')
    {
    int sign=-1;
    if(a[0]=='-'&&b[0]=='-') sign=1;
    else sign=0;
    int start1=0,start2=0,mark1=0,mark2=0,
    int end1=strlen(a),end2=strlen(b);
    //************处理a前面的0************
    for(i=sign;i<strlen(a);i++)
    if(a[i]=='.') { mark1=1; break;}

    for(i=sign;i<strlen(a);i++)
    {
    if(a[i]!='0'&&i!=strlen(a)-1) { start1=i; break;}
    else start1=strlen(a)-1;
    }
    //*************处理b前面的0****************
    for(i=sign;i<strlen(b);i++)
    if(b[i]=='.') { mark2=1; break;}

    for(i=sign;i<strlen(b);i++)
    {
    if(b[i]!='0'&&i!=strlen(b)-1) { start2=i; break;}
    else start2=strlen(b)-1;
    }
    //************处理a含有“.”后面的0***************
    if(mark1==1)
    {
    for(i=strlen(a)-1;i>=sign;i--)
    if(a[i]!='0')
    {
    if(a[i]=='.') { end1=i; break;}
    else { end1=i; break;}
    }
    }
    //************处理b含有“.”后面的0***********
    if(mark2==1)
    {
    for(i=strlen(b)-1;i>=sign;i--)
    if(b[i]!='0')
    {
    if(b[i]=='.') { end2=i; break;}
    else { end2=i; break;}
    }
    }
    //***********处理0的情况*************
    if(end1==start1) start1=0;
    if(end2==start2) start2=0;
    //cout<<start1<<" "<<end1<<endl;
    //cout<<start2<<" "<<end2<<endl;
    if(end1-start1==end2-start2)
    {
    int flag=0;
    for(i=start1,j=start2;j<end2,i<end1;i++,j++)
    if(a[i]==b[j]) flag++;

    if(flag==end1-start1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    }
    else cout<<"NO"<<endl;
    }
    else cout<<"NO"<<endl;
    }
    return 0;
    }

    java版:

    View Code
    import java.io.*;
    import java.util.Scanner;
    import java.math.BigDecimal;

    class Main
    {
    public static void main(String [] args)
    {
    Scanner cin
    = new Scanner(new BufferedInputStream(System.in));
    BigDecimal a , b ;
    while(cin.hasNext())
    {
    a
    =cin.nextBigDecimal();
    b
    =cin.nextBigDecimal();
    a
    =a.stripTrailingZeros();
    b
    =b.stripTrailingZeros();

    int c=a.compareTo(b);
    if(c==0)
    System.out.println(
    "YES");
    else System.out.println("NO");
    }
    }
    }
  • 相关阅读:
    web架构
    网站开发的学习交流 系统架构 负载均衡
    数据库连接
    OpenCV4【12】边缘检测
    python基础_格式化输出(%用法和format用法)
    Python之telnetlib模块
    根据文字或图片来生成用于Banner输出的字符画
    Python3 range() 函数用法
    Python psutil cpu_percent调用说明
    @staticmethod和@classmethod的用法
  • 原文地址:https://www.cnblogs.com/FCWORLD/p/2025175.html
Copyright © 2011-2022 走看看