题目地址:HDU2054
将读出的浮点数保存在字符数组中(声明大小或者new一个),除去前置零和小数点后的后置零,若小数点后数全为零,则连小数点一起去掉。
注意:去掉后置零时 *p--=0 的表达方式。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
void A(char *s)
{
int len=strlen(s);
char *p=s+len-1;
if(strchr(s,'.'))
while(*p=='0')*p--=0;
if(*p=='.') *p=0;
}
int main()
{
char m[100000],n[1000000];
while(scanf("%s%s",&m,&n)!=EOF)
{
char *pm=m;
char *pn=n;
while(*pm=='0') pm++;
while(*pn=='0') pn++;
A(pm);A(pn);
if(strcmp(pm,pn))
cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
}