| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
谁能优化一下这个类?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator