Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁能优化一下这个类?

Posted by 200593141 at 2007-07-18 10:56:35 on Problem 1056
class elem
{
	friend istream& operator >> ( istream &input, elem &obj )
	{
	   cin >> obj.code ;
	   obj.Convert() ;
	   return input ;
	}
public:
	bool operator == ( const elem &other )
	{
	   int temple = length - other.length ;
	   if( temple > 0 )
		   return (value >> temple) == other.value ; 
	   else if( temple < 0 )
	       return value == (other.value >> -temple) ;
	   else
		   return false ;
	}
	void Convert()
	{
	   int ptr = 0 ;
	   value = 0 ;
	   length = strlen( code ) ;
	   for( ; code[ptr] != '\0'; ptr++ )
	   {
	      value <<= 1 ;
		  if( code[ptr] == '1' )
			  value++ ;		
	   }
	}
private:
	char code[11] ;
	int length ;
	int value ;
} ;

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator