• HDUOJ-----A == B ?


    A == B ?

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 49403    Accepted Submission(s): 7593

    Problem Description
    Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
     
    Input
    each test case contains two numbers A and B.
     
    Output
    for each case, if A is equal to B, you should print "YES", or print "NO".
     
    Sample Input
    1 2
    2 2
    3 3
    4 3
     
    Sample Output
    NO
    YES YES NO
     
    Author
    8600 && xhd
     
    Source
     

    此题解法:分整数和小数两部分来比较即可!!但要注意的事情还是比较多的

    需要考虑:

    +0.000    0.00

    YES

    +0.00 -0.00

    YES

    +0001.00 1

    YES

    +000.0000100  .00001

    YES

    代码如下:

     1 #include<cstdio>
     2 #include<cstring>
     3 #define MAX 20000
     4 char a[MAX],b[MAX];
     5 char ra[MAX],apoint[MAX],
     6      rb[MAX],bpoint[MAX];
     7 void func(char *a,char *ra,char *apoint)
     8 {
     9     int i=0,k=0;
    10     bool flag=true;
    11     int len=strlen(a);
    12     if(*a=='+')i++;
    13     else if(a[0]=='-')
    14     {
    15         ra[k++]='-' ;
    16         i=k;
    17     }
    18     for( ; a[i]=='0'&&i<len ; i++ );
    19 
    20     for( ;a[i]!='.'&&i<len ; i++ )
    21     {  
    22         ra[k++] = a[i] ;
    23     }
    24     int j;
    25          a[i]=='.'? i++ : i ;
    26    for(j=len-1;a[j]=='0'&&j>=i;j--);
    27    
    28    for(k=0 ; i<=j ; i++)
    29     {
    30         apoint[k++]=a[i];
    31     }
    32 }
    33 
    34 int main( void )
    35 {
    36     while(scanf("%s%s",a,b)!=EOF)
    37     {
    38         memset(ra,'',sizeof ra);
    39         memset(apoint,'',sizeof apoint);
    40         memset(rb,'',sizeof rb);
    41         memset(bpoint,'',sizeof bpoint);
    42         func(a,ra,apoint);
    43         func(b,rb,bpoint);
    44       if(strcmp(ra,rb)==0&&strcmp(apoint,bpoint)==0)
    45           puts("YES");
    46       else if((*rb=='-'&&*(rb+1)=='')&&strcmp(apoint,bpoint)==0)
    47           puts("YES");
    48      else if(*ra=='-'&&*(ra+1)==''&&strcmp(apoint,bpoint)==0)
    49                puts("YES");
    50      else
    51           puts("NO");
    52     }
    53     return 0;
    54 }
    View Code
  • 相关阅读:
    iframe脸面的页面和父页面之间的交互方法
    iframe高度自适应
    获取html元素所在页面的坐标
    自制的几个jquery插件
    将DataTable转换成Json格式
    QL 获取当前日期,年、月、日、周、时、分、秒
    DropdownList异步刷新GridView数据
    图片热区——map的用法
    Chart控件文档
    母版页改变被嵌套的页面中的控件ID的解决方法
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3203216.html
Copyright © 2020-2023  润新知