HDU2054 A == B ?【大数】

    xiaoxiao2025-08-09  10

    A == B ?

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 116725    Accepted Submission(s): 18601 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 校庆杯Warm Up

    问题链接:HDU2054 A == B ?。

    问题简述:

      输入两个数,比较两个数的大小,相等的话输出"YES",不等的话输出"NO"。

    问题分析:

      可能是一个大数,需要特殊处理。如果没有小数点,就可以直接进行字符串比较,如果有小数点,则需要处理小数点后多余的"0",即删除那些"0",然后再进行字符串比较。

    程序说明:

      编写函数mystrchange()对大数进行调整,去掉小数点后的"0"。需要注意的是数可能很大,所以字符数组元素需要有10000个。实际试算结果是,数组元素4096个是不行的,算不出正确结果。

    AC的C语言程序如下:

    /* HDU2054 A == B ? */ #include <stdio.h> #include <string.h> #define MAXN 100000 char s[MAXN], t[MAXN]; void mystrchange(char s[]) { if(strstr(s, ".")) { int end = strlen(s) - 1; while(s[end] == '0') end--; if(s[end] == '.') s[end] = '\0'; else s[end+1] = '\0'; } } int main(void) { while(scanf("%s%s", s, t) != EOF) { mystrchange(s); mystrchange(t); if(strcmp(s, t)) printf("NO\n"); else printf("YES\n"); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1301553.html
    最新回复(0)