HDU 2054 A == B ?
JAVA
import java.io.*;
import java.util.*;
import java.math.*;
import java.io.BufferedInputStream;
public class aa
{
public static void main( String[] args )
{
BigDecimal a,b;
Scanner cin = new Scanner(System.in);
while( cin.hasNext() )
{
a = cin.nextBigDecimal();
b = cin.nextBigDecimal();
a = a.stripTrailingZeros();
b = b.stripTrailingZeros();
System.out.println( a.compareTo(b) == 0 ? "YES" : "NO" );
}
}
}
这题是两大数是否相等的题,这里巧用指针把字符串前面多余的0和字符串后面多余的0处理掉( 为了处理这种情况00200.01 200.0100 ),其实把这题,做了,很多字符串处理的问题都能过了.....
#include<stdio.h>
#include<string.h>
#define max 100024
char str1[max] = {0},str2[max] = {0};
void deal( char str[] )
{
char *p = str;
while( *p == '0' )//处理前面的0
++p;
strcpy( str,p );
if( strchr( str,'.' ) )//处理小数点后面的0
{
int len = strlen( str );
char *q = str + len - 1;
while( *q == '0' )
*(q--) == 0;
*q = 0;//把小数点去掉,以免出现1 与 1. 这种数据
}
}
int main( )
{
while( scanf( "%s%s",str1,str2 ) != EOF )
{
deal( str1 );
deal( str2 );
if( !( strcmp( str1,str2 ) ) )
puts( "YES" );
else
puts( "NO" );
}
}
本人还是新手 ,转载请注明来自Lvsi‘s home
浙公网安备 33010602011771号