一道看似很简单的判断A==B问题

xiaoxiao2021-02-28  131

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

#include<stdio.h> #include<string.h> void result(char *a); int main() { char a[1000000]; char b[1000000]; while(~scanf("%s %s",a,b))//遇见EOF停止 { result(a);result(b); if(strcmp(a,b)==0) printf("YES\n"); else printf("NO\n"); } return 0; } void result(char *a) { int i; char t[1000000]; int flag=0; for(i=0;i<strlen(a);i++)//将小数点之前数字多余0去掉 { if(a[i]!='0') break; } strcpy(t,a+i);//储存去除前面的0的字符串 for(i=0;i<strlen(t);i++)//判断是否有‘.’,如果没有就不需要删除小数点之后多余的0 { if(t[i]=='.') { flag=1; break; } } if(flag) { for(i=strlen(t)-1;i>=0;i--) { if(t[i]=='0')//从最后计数,将最后多余0变为结束符号 t[i]='\0'; else break; } } if(t[i]=='.') t[i]='\0'; strcpy(a,t);

本题最坑就在于它的数字可以很长,必须使用字符串进行处理,如果遇见000001.001 和1.001你必须判断是否正确!

转载请注明原文地址: https://www.6miu.com/read-22142.html

最新回复(0)