LeeBlog

导航

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" );
         }  
} 

posted on 2011-04-09 13:47  LeeBlog  阅读(739)  评论(0编辑  收藏  举报