示例#1
0
文件: addbinary.cpp 项目: elsucai/LC
    string addBinary(string a, string b) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        string ret = "";
		if(a.empty())
			return b;
		if(b.empty())
			return a;
			
		int sizea = a.size();
		int sizeb = b.size();
		
		int i, j, carry, remainder;
		carry = 0;
		
		for(i = sizea-1, j = sizeb-1; i >= 0 && j >= 0; i--, j--){
			onebit(a[i]-'0', b[j]-'0', carry, remainder, ret);
		}
		
		while(i >= 0){
			onebit(a[i]-'0', 0 , carry, remainder, ret);
			i--;
		}
		
		while(j >= 0){
			onebit(b[j]-'0', 0 , carry, remainder, ret);
			j--;
		}
		
		// carry
		if(carry)
			ret = "1"+ret;
		return ret;
    }
int combinable(TERM tt1,TERM tt2)
{
    if(((tt1.t^tt2.t)==(tt1.f^tt2.f))&& onebit(tt1.t^tt2.t))
    return TRUE;
    else
    return FALSE;
}