2054 大数模拟 水题(略坑)

来源:互联网 发布:浅谈移动通信网络优化 编辑:程序博客网 时间:2024/05/22 17:15
A == B ?Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 89356    Accepted Submission(s): 14145Problem DescriptionGive you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".Inputeach test case contains two numbers A and B.Outputfor each case, if A is equal to B, you should print "YES", or print "NO".Sample Input1 22 23 34 3Sample OutputNOYESYESNOAuthor8600 && xhdSource校庆杯Warm UpRecommendlinle
#include<stdio.h>#include<string.h>char A[100000];char B[100000];void change(char s[]){    int point=0,len=strlen(s);    for(int i=len-1;i>=0;i--)        if(s[i]=='.') {point=1;break;}    if(point)    {        int K;        for(K=len-1;s[K]=='0';K--) s[K]='\0';        if(s[K]=='.') s[K]='\0';    }}int main(void){    while(scanf("%s %s",A,B)!=EOF)    {        int lenA=strlen(A),lenB=strlen(B);        //先排除前置0        int top_i=0,top_j=0;        while(A[top_i]=='0'&&top_i<lenA-1&&A[top_i+1]!='.') top_i++;//不减到最后一位以防是0        while(B[top_j]=='0'&&top_j<lenB-1&&B[top_j+1]!='.') top_j++;        //再排除后置0        change(A);        change(B);        int flag=strcmp(A+top_i,B+top_j);        if(!flag) printf("YES\n");        else printf("NO\n");    }    return 0;}/*这题WA了相当多此来找一个错误,结果是因为复制相同代码段时变量名没改全,还有逆向读取数组元素时用了i++这种低级错误*/
0 0
原创粉丝点击