int main( void ) { SWORD a, b; SWORD a1, b1; SWORD mina = 0, minb = 0; FILE *IN, *OUT; int firsttime = 1; if ((IN = fopen("gcm.in", "rt")) == NULL) return 1; if ((OUT = fopen("gcm.out", "wt")) == NULL) { fclose(IN); return 1; } fscanf(IN, "%I64d", &a); fscanf(IN, "%I64d", &b); for (a1 = min(a, b); a1 <= max(a, b); a1++) { b1 = a * b / a1; if (NOD(a, b) == NOD(a1, b1) && NOK(a, b) == NOK(a1, b1)) if ((my_abs(a1 - b1) < my_abs(mina - minb)) || firsttime) { mina = a1; minb = b1; firsttime = 0; } } fprintf(OUT, "%I64d %I64d", mina, minb); fclose(IN); fclose(OUT); return 0; }
int main(void) { FILE *FIn, *FOut; int i, j, max, a, b, min, x, y, nod, nok; if ((FIn = fopen("gcm.in", "rt")) == NULL) return 0; if ((FOut = fopen("gcm.out", "wt")) == NULL) return 0; fscanf(FIn, "%d%d", &a, &b); if (a > b) max = a, min = a - b; else max = b, min = b - a; nod = NOD(a, b); nok = NOK(a, b); x = a; y = b; for (i = 1; i <= max; i++) { j = (int)(a * b / i); if (i > j) break; if (min > Minus(i, j) && nod == NOD(i, j) && nok == NOK(i, j)) x = i, y = j; } fprintf(FOut, "%d %d", x, y); fclose(FIn); fclose(FOut); }
/** * Base class implementation of destructor. * * @param _this This instance */ void CDlpObject_Destructor(CDlpObject* _this) { SWord* lpWord; hnode_t* hn; hscan_t hs; DEBUGMSG(-1,"CDlpObject_Destructor for '%s'",_this->m_lpInstanceName,0,0); /* Detach external instances */ hash_scan_begin(&hs,_this->m_lpDictionary); while ((hn = hash_scan_next(&hs))!=NULL) { DLPASSERT((lpWord = (SWord*)hnode_get(hn))!=NULL); /* NULL entry in dictionary */ if ( lpWord->nWordType == WL_TYPE_FIELD && lpWord->ex.fld.nType == T_INSTANCE ) { CHECK_IPTR(*(CDlpObject**)lpWord->lpData,lpWord->ex.fld.nISerialNum); if (CDlpObject_GetParent(*(CDlpObject**)lpWord->lpData)!=_this) *(CDlpObject**)lpWord->lpData = NULL; } } #ifndef __NORTTI /* Clear words */ if(NOK(CDlpObject_UnregisterAllWords(_this)) ) IERROR(_this,ERR_DESTROY," Error while UnregisterAllWords of instance %s !", _this->m_lpInstanceName,0); /* Clear operators */ if(NOK(CDlpObject_UnregisterAllOperators(_this)) ) IERROR(_this,ERR_DESTROY," Error while UnregisterAllOperators of instance %s !", _this->m_lpInstanceName,0); #endif /* Destroy dictionaries */ if(!hash_isempty(_this->m_lpObsIds)) IERROR(_this,ERR_DESTROY, " Destructor of instance '%s': hash 'ObsIds' not empty !", _this->m_lpInstanceName,0); if(!hash_isempty(_this->m_lpDictionary)) IERROR(_this,ERR_DESTROY, " Destructor of instance '%s': hash 'Dictionary' not empty !", _this->m_lpInstanceName,0); if(!hash_isempty(_this->m_lpOpDict)) IERROR(_this,ERR_DESTROY, " Destructor of instance '%s': hash 'OpDict' not empty !", _this->m_lpInstanceName,0); hash_destroy(_this->m_lpObsIds ); hash_destroy(_this->m_lpDictionary); hash_destroy(_this->m_lpOpDict); #ifdef __cplusplus /* Unregister */ dlp_xalloc_unregister_object(_this); #endif }
INT16 CGEN_PUBLIC CCPproc::QuantizeImpl(CData* idCep, INT32 nCS, INT32 nCC, INT32 nQ, CData* idRes) { INT32 iRec; INT32 nRec; INT32 nComp; INT32 iComp; INT16 ret = O_K; if(idCep == NULL || CData_GetNComps(idCep) <= 0) return NOT_EXEC; if((nQ != 8) && (nQ != 16) && (nQ != 32) && (nQ != 64)) return NOT_EXEC; nRec = idCep->GetNRecs(); nComp = idCep->GetNComps(); if(nCS > nComp) return NOT_EXEC; if(nCS < 0) nCS = 0; if((nCC < 0) || ((nCS+nCC) > nComp)) nCC = nComp - nCS; for(iComp = nCS; iComp < nCS+nCC; iComp++) { if(!dlp_is_float_type_code(idCep->GetCompType(iComp))) return NOT_EXEC; } CData_Copy(idRes, idCep); for(iRec = 0; iRec < nRec; iRec++) { ret = dlm_cep_quantize((FLOAT64*)idRes->XAddr(iRec,nCS),nCC,nQ); if(NOK(ret)) return ret; } CData_Mark(idRes, nCS, nCC);idRes->m_bMark = TRUE; CData_Tconvert(idRes, idRes, (nQ == 8) ? T_CHAR : (nQ == 16) ? T_SHORT : (nQ == 32) ? T_INT : T_LONG); idRes->m_bMark = FALSE;CData_Unmark(idRes); return O_K; }
static void do_conf() { char c = 0; char line[64]; int args, id, num, gain, min, max; struct chan *channel; gets(line); args = sscanf(line, "%c %u %u %i %i", &c, &num, &gain, &min, &max); if (args > 0) { id = CHANNEL_ID(c); if (id >= CHANNELS) NOK(); else if (args == 1) { channel = conf_get(id); printf("%c %u %u %i %i\n", c, channel->num, channel->gain, channel->min, channel->max); } else { int tmp; input_stop(); channel = conf_get(id); tmp = channel->gain; channel->num = limit(num, 0, AD_CHANNELS); if (args >= 3) { channel->gain = limit(gain, AD_GAIN_MIN, AD_GAIN_MAX); if (tmp != channel->gain) input_calibrate(id); } if (args == 4) { max = limit(min, 0, AD_VMAX); min = limit(-min, AD_VMIN, 0); channel->min = min; channel->max = max; } else if (args >= 5) { channel->min = limit(min, AD_VMIN, AD_VMAX); channel->max = limit(max, channel->min, AD_VMAX); } printf("ok %c %u %u %i %i\n", c, channel->num, channel->gain, channel->min, channel->max); input_start(); } } else NOK(); }
static void do_abort() { if (state_getState() == STOP) { // acknowledge error const Pin stop = PIN_STOP; if (PIO_Get(&stop)) { state_reset(); OK(); } else NOK(); } else { state_reset(); OK(); } }
int main(void) { FILE *FIn, *FOut; int i, j, max, a, b, min, x, y, nod, nok; if ((FIn = fopen("gcm.in", "rt")) == NULL) return 0; if ((FOut = fopen("gcm.out", "wt")) == NULL) return 0; fscanf(FIn, "%d%d", &a, &b); if (a > b) max = a, min = a - b; else max = b, min = b - a; nod = NOD(a, b); nok = NOK(a, b); for (i = 1; i <= max; i++) for (j = 1; j <= max; j++) if (nod == NOD(i, j) && nok == NOK(i, j) && min > Minus(i, j)) x = j, y = i; fprintf(FOut, "%d %d", x, y); fclose(FIn); fclose(FOut); }
/** * Copies the global class registry into the instances dictionary. * * @param _this * This instance * @param bAutoInst * If <code>TRUE</code> create auto-instances * @return <code>O_K</code> if successful, a (negative) error code otherwise **/ INT16 CDlpObject_LoadClassRegistry(CDlpObject* _this, BOOL bAutoInst) { INT32 nC = 0; const SWord* lpFactoryWord = NULL; CDlpObject* lpInst = NULL; for (nC=0; nC<__nXClassRegistry; nC++) { lpFactoryWord = &__lpClassRegistry[nC]; DLPASSERT(lpFactoryWord && lpFactoryWord->nWordType==WL_TYPE_FACTORY); /* Call installation function */ if (NOK((lpFactoryWord->ex.fct.lpfInstall)(_this))) continue; /* Register singleton or auto instance in dictionary */ if ((lpFactoryWord->nFlags & (CS_SINGLETON|CS_AUTOINSTANCE)) && bAutoInst) { SWord newword; const char* lpsInstanceName = lpFactoryWord->ex.fct.lpAutoname; if (lpFactoryWord->nFlags & CS_SINGLETON) lpsInstanceName = lpFactoryWord->lpName; if (dlp_strlen(lpFactoryWord->lpName) ==0) continue; lpInst = (lpFactoryWord->ex.fct.lpfFactory)(lpsInstanceName); if (!lpInst) continue; memset(&newword,0,sizeof(SWord)); newword.nWordType = WL_TYPE_INSTANCE; newword.lpData = lpInst; strcpy(newword.lpName,lpsInstanceName); strcpy(newword.lpObsname,lpFactoryWord->lpObsname); CDlpObject_RegisterWord(_this,&newword); lpInst->m_nInStyle |= IS_GLOBAL; } /* Register class factory in dictionary */ if (!(lpFactoryWord->nFlags & CS_SINGLETON)) { CDlpObject_RegisterWord(_this,lpFactoryWord); } } return O_K; }
void command_invoke(char c) { if (strchr(cmask[state_getState()], c) == 0) { TRACE_DEBUG("CLI: command %c not accepted\n", c); NOK(); } else { int i = 0; struct command cmd = commands[0]; while (cmd.action) { if (cmd.c == c) { TRACE_DEBUG("CLI: command %c invoked\n", c); cmd.action(); break; } cmd = commands[++i]; } } }