int main(){
	int i,n;
	char ip[MAX_B];

	scanf("%s",ip);
	n = strlen(ip);
	for(i = 0; i < n; ++i)	bin |= ((ip[n-1-i]-'0')<<i);


	scanf("%s",inc);
	t= strlen(inc);

	for(i = 0; i < n; ++i){
		bin ^= (1<<i);
		tsize = 0;
		memset(ter,'0',sizeof(char)*MAX_T);
		ternary(bin);
		if(cmp()) break;
		bin ^= (1<<i);
	}

	printf("%d\n",bin);

	return 0;
}
示例#2
0
int main()
{
    long n;
    while ( scanf("%ld", &n) == 1)
    {
        if (n < 0) break;
        printf("%lld\n", ternary(n) );
    }
    return 0;
}
示例#3
0
bool SRExpressionsParser::assign(double* r)
{
	char t[SR_VARLEN + 1];

	if (type == VT_VAR)
	{
		if((*expression == '=')&&(expression[1] != '='))
		{
			strcpy(t, token.value());
			parse();
			parse();
			if(!*token.value())
			{
				ClearVar(t);
				return true;
			}
			ternary(r);
			if(!SetValue(t, *r, true))
				throw(E_MAXVARS);
			return true;
		}
	}
	if (type == VT_DEF)
	{
		if((*expression == '=')&&(expression[1] != '='))
		{
			strcpy(t, token.value());
			parse();
			parse();
			if(!*token.value())
			{
				ClearVar(t);
				return true;
			}
			ternary(r);
			if(!SetValue(t, *r, true))
				throw(E_MAXVARS);
			return true;
		}
	}
	ternary(r);
	return false;
}
示例#4
0
bool MicroCode::execute(VM* vm, Opcode opcode) const
{
  const size_t stackSize = vm->stackSize();
  
  Value v1 = Value::INVALID, v2 = Value::INVALID, v3 = Value::INVALID;
  
  if (opcodeData[opcode].hasTernary && stackSize >= 3)
  {
    v3 = vm->pop();
    v2 = vm->pop();
    v1 = vm->pop();
    
    auto function = findBestOverload({ opcode, v1.type, v2.type, v3.type });
    
    if (function)
    {
      function->ternary(vm, v1, v2, v3);
      return true;
    }
  }
  
  if (opcodeData[opcode].hasBinary && stackSize >= 2)
  {
    if (v3.valid())
    {
      v2 = v3;
      v1 = v2;
    }
    else
    {
      v2 = vm->pop();
      v1 = vm->pop();
    }
    
    auto function = findBestOverload({ opcode, v1.type, v2.type, TYPE_NONE });
    
    if (function)
    {
      function->binary(vm, v1, v2);
      return true;
    }
  }
  
  if (opcodeData[opcode].hasUnary && stackSize >= 1)
  {
    if (v3.valid())
      v1 = v3;
    else if (v2.valid())
      v1 = v2;
    else
      v1 = vm->pop();
    
    auto function = findBestOverload({ opcode, v1.type, TYPE_NONE, TYPE_NONE });
    
    if (function)
    {
      function->unary(vm, v1);
      return true;
    }
  }
  
  auto function = findBestOverload({ opcode, TYPE_NONE, TYPE_NONE, TYPE_NONE });
  
  if (function)
  {
    function->nullary(vm);
    return true;
  }
  
  
  /* push values back */
  if (v1.valid()) vm->push(v1);
  if (v2.valid()) vm->push(v2);
  if (v3.valid()) vm->push(v3);
  
  
  return false;
}
void ternary(int dec){
	if(!dec) return;
	ternary(dec/3);
	ter[tsize++] = dec%3+'0';
}