hdu2054

http://acm.hdu.edu.cn/showproblem.php?pid=2054

很烦的题~~

View Code
#include"iostream"
#include
"string"
using namespace std;
int i,j,L1,L2;
char a[20000],b[20000];
int main()
{
while(scanf("%s %s",&a,&b)!=EOF)
{
if(a[0]=='-'&&b[0]=='-'||a[0]!='-'&&b[0]!='-')
{
int sign=-1;
if(a[0]=='-'&&b[0]=='-') sign=1;
else sign=0;
int start1=0,start2=0,mark1=0,mark2=0,
int end1=strlen(a),end2=strlen(b);
//************处理a前面的0************
for(i=sign;i<strlen(a);i++)
if(a[i]=='.') { mark1=1; break;}

for(i=sign;i<strlen(a);i++)
{
if(a[i]!='0'&&i!=strlen(a)-1) { start1=i; break;}
else start1=strlen(a)-1;
}
//*************处理b前面的0****************
for(i=sign;i<strlen(b);i++)
if(b[i]=='.') { mark2=1; break;}

for(i=sign;i<strlen(b);i++)
{
if(b[i]!='0'&&i!=strlen(b)-1) { start2=i; break;}
else start2=strlen(b)-1;
}
//************处理a含有“.”后面的0***************
if(mark1==1)
{
for(i=strlen(a)-1;i>=sign;i--)
if(a[i]!='0')
{
if(a[i]=='.') { end1=i; break;}
else { end1=i; break;}
}
}
//************处理b含有“.”后面的0***********
if(mark2==1)
{
for(i=strlen(b)-1;i>=sign;i--)
if(b[i]!='0')
{
if(b[i]=='.') { end2=i; break;}
else { end2=i; break;}
}
}
//***********处理0的情况*************
if(end1==start1) start1=0;
if(end2==start2) start2=0;
//cout<<start1<<" "<<end1<<endl;
//cout<<start2<<" "<<end2<<endl;
if(end1-start1==end2-start2)
{
int flag=0;
for(i=start1,j=start2;j<end2,i<end1;i++,j++)
if(a[i]==b[j]) flag++;

if(flag==end1-start1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else cout<<"NO"<<endl;
}
else cout<<"NO"<<endl;
}
return 0;
}

java版:

View Code
import java.io.*;
import java.util.Scanner;
import java.math.BigDecimal;

class Main
{
public static void main(String [] args)
{
Scanner cin
= new Scanner(new BufferedInputStream(System.in));
BigDecimal a , b ;
while(cin.hasNext())
{
a
=cin.nextBigDecimal();
b
=cin.nextBigDecimal();
a
=a.stripTrailingZeros();
b
=b.stripTrailingZeros();

int c=a.compareTo(b);
if(c==0)
System.out.println(
"YES");
else System.out.println("NO");
}
}
}
posted @ 2011-04-22 18:15  聊聊IT那些事  阅读(671)  评论(0编辑  收藏  举报