//输入两个链表,找出它们第一个公共结点。 //先算出两个链表长度,求差,让长的先走相差的长度,再同时走就找到第一个交点了。 ListNode *FindConmmonNode(ListNode *L1, ListNode *L2) { int len1 = GetLen(L1); int len2 = GetLen(L2); int dilen = len1 - len2; int i = 0; ListNode *pHeadlong = L1; ListNode *pHeadshort = L2; if (len2 > len1); { pHeadlong = L2; pHeadshort = L1; dilen = L2 - L1; } for (i = 0; i < dilen; i++) { pHeadlong = pHeadlong->next; } while ((pHeadlong != NULL) && (pHeadshort != NULL) && (pHeadlong != pHeadshort)) { pHeadlong = pHeadlong->next; pHeadshort = pHeadshort->next; } ListNode *pFindNode = pHeadlong; return pFindNode; }
TString<T> TString<T>::Right(int nCount) const { _ASSERT(nCount >= 0); if (nCount < GetLen()) { return &pBuf[GetLen() - nCount]; } else { return *this; } }
int CategoricalProbTree::GetNextBranch(const AttrValue* attr) const { int branch = static_cast<const EnumAttrValue*>(attr)->Value(); ProbInterval PI = this->GetProbInterval(branch); if (PI.l == PI.r) { // We found the "omitted" categorical values. Recover it with the most likely category Prob current_best; for (size_t i = 0; i <= prob_segs_.size(); ++i ) { if (GetLen(this->GetProbInterval(i)) > current_best) { current_best = GetLen(this->GetProbInterval(i)); branch = i; } } } return branch; }
FileStream::FileStream(StdString filename) { ipos = 0; Console::WriteLine(StdString("Opening ")+filename); fpointer = fopen(filename.rstr(),"r+b"); GetLen(); }
int ReadBuf(char *inFile, SECItem *item) { int len; int ret; PRFileDesc* fd = PR_Open(inFile, PR_RDONLY, 0); if (NULL == fd) { SECU_PrintError("symkeyutil", "PR_Open failed"); return -1; } len = GetLen(fd); if (len < 0) { SECU_PrintError("symkeyutil", "PR_GetOpenFileInfo failed"); return -1; } item->data = (unsigned char *)PORT_Alloc(len); if (item->data == NULL) { fprintf(stderr,"Failed to allocate %d to read file %s\n",len,inFile); return -1; } ret = PR_Read(fd,item->data,item->len); if (ret < 0) { SECU_PrintError("symkeyutil", "PR_Read failed"); PORT_Free(item->data); item->data = NULL; return -1; } PR_Close(fd); item->len = len; return 0; }
void R_FIStr( void ) { //================= uint width; byte blanks; uint length; ftnfile *fcb; char *src; char PGM *ptr; fcb = IOCB->fileinfo; width = IOCB->fmtptr->fmt4.fld1; if( IOCB->typ != PT_CHAR ) { ptr = IORslt.pgm_ptr; length = GetLen(); } else { ptr = IORslt.string.strptr; length = IORslt.string.len; } if( width == 0 ) { width = length; } if( width >= length ) { fcb->col += width - length; width = length; } ChkBuffLen( width ); blanks = length - width; src = &fcb->buffer[ fcb->col ]; pgm_memput( ptr, src, width ); pgm_memset( ptr + width, ' ', blanks ); fcb->col += width; }
static void FOString( uint width ) { //================================== ftnfile *fcb; uint length; fcb = IOCB->fileinfo; if( IOCB->typ != PT_CHAR ) { length = GetLen(); } else { length = IORslt.string.len; } if( width == 0 ) { width = length; } if( fcb->col + width > fcb->bufflen ) { IOErr( IO_BUFF_LEN ); } if( width > length ) { SendChar( ' ', width - length ); width = length; } if( IOCB->typ == PT_CHAR ) { SendStrRtn( IORslt.string.strptr, width ); } else { SendStrRtn( (char *)&IORslt, width ); } }
void Menu::CreateMenu(LPCSTR s,lpRLCFont f,lpRLCFont f1,fnc* ff,int style){ if(!int(items))delete((void*)items); items=new(char[strlen(s)+1]); memcpy((void*)items,s,strlen(s)+1); NItems=GetAmount(); font=f; font1=f1; NZones=NItems; ItemLy=GetRLCHeight(font->RLC,font->FirstSymbol+'W'); MenuLy=ItemLy*NItems; StartY=(RSCRSizeY-MenuLy)/2; int Ly=0; for(int i=0;i<NItems;i++){ LPCSTR ss=GetNstr(i); int Lx=GetLen(ss); Zone[i].x=(COPYSizeX-Lx)/2+100; Zone[i].y=StartY+i*ItemLy; Zone[i].x1=Zone[i].x+Lx; Zone[i].y1=Zone[i].y+ItemLy; }; RedrawBackground=ff; Active=style&1?true:false; MakeShift=style&2?true:false; ChangeFont=style&4?true:false; EraseOnChoose=style&8?true:false; };
void WaveletMatrixBuilder::BuildWithAVals(WaveletMatrix& wm, vector<uint32_t>& avals){ uint32_t max_val = GetMax(vals_); uint32_t max_depth = GetLen(max_val); wm.max_val_ = max_val; wm.layers_.resize(max_depth); vector<uint32_t> zeros; vector<uint32_t> ones; vector<uint32_t> zero_avals; vector<uint32_t> one_avals; zeros.swap(vals_); zero_avals = avals; for (uint32_t depth = 0; depth < max_depth; ++depth){ vector<uint32_t> next_zeros; vector<uint32_t> next_ones; vector<uint32_t> next_zero_avals; vector<uint32_t> next_one_avals; RSDicBuilder rsdb; FilterWithAVals(zeros, zero_avals, max_depth - depth - 1, next_zeros, next_ones, next_zero_avals, next_one_avals, rsdb); FilterWithAVals(ones, one_avals, max_depth - depth - 1, next_zeros, next_ones, next_zero_avals, next_one_avals, rsdb); zeros.swap(next_zeros); ones.swap(next_ones); zero_avals.swap(next_zero_avals); one_avals.swap(next_one_avals); rsdb.Build(wm.layers_[depth]); } copy(zero_avals.begin(), zero_avals.end(), avals.begin()); copy(one_avals.begin(), one_avals.end(), avals.begin() + zero_avals.size()); }
void SSRecord::Dump (std::ostream& os) const { os << "Offset: " << GetOffset (); os << " Type: " << GetRecordType (); os << " Len: " << GetLen(); std::string validity = IsValid() ? "valid" : "invalid"; os << " crc: " << m_Header.checksum << " -> " << validity << std::endl; }
int kGUIText::GetLineNum(unsigned int charindex) { int startindex,endindex,midindex; unsigned int endchar; kGUIInputLineInfo *lbptr; if(m_llnum<2) return(0); else if(charindex>=GetLen()) return(m_llnum-1); /* binary search */ startindex=0; endindex=m_llnum-1; /* make sure split list is accurate! */ lbptr=GetLineInfo(endindex); assert(lbptr->endindex==(GetLen()-1) || lbptr->endindex==(GetLen()),"Split list is NOT up to date!"); do { midindex=(startindex+endindex)>>1; lbptr=GetLineInfo(midindex); endchar=lbptr->endindex; if(lbptr->hardbreak==false) --endchar; if(charindex<lbptr->startindex) { if(endindex==midindex) --endindex; else endindex=midindex; } else if(charindex>endchar) { if(startindex==midindex) ++startindex; else startindex=midindex; } else return(midindex); }while(1); }
TString<T>& TString<T>::DiffCat(const T *pStart, const T *pEnd) { _ASSERT(pBuf && pStart && pEnd); int StrLen = pEnd - pStart; SetAllocSize(nBufSize + StrLen); My_strncpy(GetBuffer() + GetLen(), pStart, StrLen); ReleaseBuffer(nBufSize + StrLen - 1); return *this; }
TString<T>& TString<T>::Cat(const T *pStr) { _ASSERT(pBuf && pStr); int StrLen = My_lstrlen(pStr); SetAllocSize(nBufSize + StrLen); My_lstrcpy(GetBuffer() + GetLen(), pStr); ReleaseBuffer(nBufSize + StrLen - 1); return *this; }
void AudioBuffer::Play(HWAVEOUT handle) { ZeroMemory(&m_header, sizeof(m_header)); m_header.dwBufferLength = GetLen()/sizeof(short); m_header.lpData = (LPSTR)GetBuffer(); waveOutPrepareHeader(handle, &m_header, sizeof(m_header)); waveOutWrite(handle, &m_header, sizeof(m_header)); }
void SuffixTree<Symb,NSymb>::Move(Symb* str, int& len, Range& rng, Count& total) { Edge e; FindEdge(e, str, len); len = GetLen(e); GetRange(state, e, rng); total = GetTotal(state); BHASSERT_WITH_NO_PERFORMANCE_IMPACT(rng.high <= total); Move(e); }
TString<T>& TString<T>::Cat(const T c) { _ASSERT(pBuf); SetAllocSize(nBufSize + 1); int CurLen = GetLen(); T *p = GetBuffer(); p[CurLen] = c; p[CurLen + 1] = '\0'; ReleaseBuffer(nBufSize); return *this; }
bool operator == (const TextBuf &other) const { if (IsNull() || other.IsNull() ) { return false; } if (IsByteStr() || other.IsByteStr()) { if (GetLen() != other.GetLen()) { return false; } else if (GetLen() == 0) { return true; } else { return (memcmp(GetBuf(), other.GetBuf(), GetLen()) == 0); } } else { return (strcmp(GetBuf(), other.GetBuf()) == 0); } };
/************************************************* Function: IsRev Description: 判断是否是回文数 Calls: scanf printf Called By: 编译器 Input: 无 Output: 无 Return: 0 *************************************************/ bool IsRev(int num) { int i; int len = GetLen(num); for (i = 1; i <= len / 2; i++) { if (GetBit(num, i) != GetBit(num, len+1-i)) { return false; } } return true; }
TString<T> TString<T>::SubStr(int nIndex, int nCount) const { _ASSERT(nIndex >= 0 && nCount >= 0); TString<T> Result; if (nIndex < GetLen()) { My_strncpy(Result.GetBuffer(nCount), &pBuf[nIndex], nCount); Result.ReleaseBuffer(); } else { Result.GetBuffer(1)[0] = '\0'; Result.ReleaseBuffer(0); } return Result; }
TString<T>& TString<T>::Replace(int nIndex, int nCount, const T *szReplaceBy) { if (!pBuf || !szReplaceBy || nIndex < 0 || nCount < 0) { return *this; } TString<T> Result; Result.GetBuffer(1)[0] = '\0'; Result.ReleaseBuffer(0); // set the string to ""; we can't do it in a usual way (using a constructor or an assignment) because we don't know whether "" needs to be unicode or ansi if (nIndex > GetLen()) { nIndex = GetLen(); } if (nIndex + nCount > GetLen()) { nCount = GetLen() - nIndex; } Result.DiffCat(pBuf, pBuf + nIndex); Result += szReplaceBy; Result += pBuf + nIndex + nCount; *this = Result; return *this; }
int UpOrDown(Node *cmdHead, int cursorPos, int nodePos, char *lastBuf, char *cmd) { int i = 0; int listLen = 0; int cmdLen = 0; char *val = NULL; assert(NULL != cmdHead); if((listLen = GetLen(cmdHead)) < 1) { return 0; } if((cmdLen = strlen(cmd)) > 0) { for(i = cursorPos; i < cmdLen; ++i) { write(STDOUT_FILENO, " ", 1); } for(i = 0; i< cmdLen; ++i) { printf("\b \b"); fflush(stdout); } } memset(cmd, 0, cmdLen); if(0 == nodePos) { write(STDOUT_FILENO, lastBuf, strlen(lastBuf)); strcpy(cmd, lastBuf); } if(NULL != (val = GetVal(cmdHead, (listLen - nodePos + 1)))) { write(STDOUT_FILENO, val, strlen(val)); strcpy(cmd, val); } return 1; }
int main(){ int t; fgets(T,MAX,stdin); sscanf(T,"%d",&t); while(t--){ fgets(T,MAX,stdin); m = strlen(T); T[--m] = '\0'; fgets(P,MAX,stdin); n = strlen(P); P[--n] = '\0'; BuildFailure(); int l = 0,ans = -1; loop(i,m){ l = GetLen(T[i],l); if(l == n){ ans = i - n + 1; break; } } printf("%d\n",ans); }
void kGUIText::SetRichBGColor(unsigned int si,unsigned int ei,kGUIColor color) { unsigned int i; unsigned int l=GetLen(); RICHINFO_DEF *ri; for(i=si;i<ei;++i) { if(i==l) SetBGColor(color); else { ri=GetRichInfoPtr(i); ri->bgcolor=color; } } StringChanged(); }
void kGUIText::SetRichFontSize(unsigned int si,unsigned int ei,unsigned int fontsize) { unsigned int i; unsigned int l=GetLen(); RICHINFO_DEF *ri; for(i=si;i<ei;++i) { if(i==l) SetFontSize(fontsize); else { ri=GetRichInfoPtr(i); ri->fontsize=fontsize; } } StringChanged(); }
/* allocate the rich list and fill it with the default info */ void kGUIText::InitRichInfo(void) { int i; int num=GetLen(); RICHINFO_DEF tc; m_userichinfo=true; m_richinfo.Alloc(num); tc.fontid=GetFontID(); tc.fontsize=GetFontSize(); tc.bgcolor=m_bgcolor; tc.fcolor=GetColor(); for(i=0;i<num;++i) m_richinfo.SetEntry(i,tc); m_richinfosize=num; StringChanged(); }
void WaveletMatrixBuilder::Build(WaveletMatrix& wm){ uint32_t max_val = GetMax(vals_); uint32_t max_depth = GetLen(max_val); wm.max_val_ = max_val; wm.layers_.resize(max_depth); vector<uint32_t> zeros; vector<uint32_t> ones; zeros.swap(vals_); for (uint32_t depth = 0; depth < max_depth; ++depth){ vector<uint32_t> next_zeros; vector<uint32_t> next_ones; RSDicBuilder rsdb; Filter(zeros, max_depth - depth - 1, next_zeros, next_ones, rsdb); Filter(ones, max_depth - depth - 1, next_zeros, next_ones, rsdb); zeros.swap(next_zeros); ones.swap(next_ones); rsdb.Build(wm.layers_[depth]); } }
//--------------------------------------------------------------------------- tTJSString tTJSString::AsLowerCase() const { tjs_int len = GetLen(); if(len == 0) return tTJSString(); tTJSString ret((tTJSStringBufferLength)(len)); const tjs_char *s = c_str(); tjs_char *d = ret.Independ(); while(*s) { if(*s >= TJS_W('A') && *s <= TJS_W('Z')) *d = *s +(TJS_W('a')-TJS_W('A')); else *d = *s; d++; s++; } return ret; }
void R_FIHex( void ) { //================= uint width; int len; ftnfile *fcb; PTYPE typ; void PGM *ptr; fcb = IOCB->fileinfo; width = IOCB->fmtptr->fmt1.fld1; len = GetLen(); typ = IOCB->typ; ChkBuffLen( width ); if( typ == PT_CHAR ) { ptr = IORslt.string.strptr; } else { ptr = IORslt.pgm_ptr; if( typ == PT_CPLX_8 ) { if( IOCB->flags & IOF_FMTREALPART ) { ptr = &((scomplex *)ptr)->realpart; } else { ptr = &((scomplex *)ptr)->imagpart; } } else if( typ == PT_CPLX_16 ) { if( IOCB->flags & IOF_FMTREALPART ) { ptr = &((dcomplex *)ptr)->imagpart; } else { ptr = &((dcomplex *)ptr)->imagpart; } } } if( !FmtH2B( &fcb->buffer[ fcb->col ], width, ptr, len, typ ) ) { IOErr( IO_BAD_CHAR ); } fcb->col += width; }
void BuildFailure(){ pf[0] = 0; range(i,1,n - 1) pf[i] = GetLen(P[i],pf[i - 1]); }
int kGUIText::CalcLineList(int w) { unsigned int line; unsigned int sindex; unsigned int totalchars; unsigned int numfit; unsigned int pixwidth; unsigned int maxw; const unsigned char *t; const unsigned char *cc; const unsigned char *ce; kGUIInputLineInfo *lbptr; if(m_linelist.GetNumEntries()==0) { m_linelist.Init(1,-1); m_linelist.SetEntry(0,new kGUIInputLineInfo); } maxw=0; line=0; sindex=0; t=(const unsigned char *)GetString(); totalchars=GetLen(); if((!t) || (!totalchars)) { lbptr=m_linelist.GetEntry(0); lbptr->startindex=sindex; lbptr->endindex=sindex; lbptr->pixwidth=0; lbptr->hardbreak=true; lbptr->pixheight=GetLineHeight(); m_lltotalheight=lbptr->pixheight+2; lbptr->ty=0; lbptr->by=m_lltotalheight-1; m_llnum=1; return(0); } m_lltotalheight=0; do{ numfit=CalcFitWidth(sindex,totalchars-sindex,w,&pixwidth); if(pixwidth>maxw) maxw=pixwidth; /* go back and break on a space, unless there are no spaces */ if(!numfit) { if(t[sindex]!=10) /* supposed to be a blank line? */ numfit=totalchars-sindex; /* rest of line */ } else { cc=t+sindex; ce=cc+numfit; if(ce[0]!=10 && ce[0]) { while((ce[-1]!=' ') && (ce>cc)) --ce; if(ce!=cc) /* only if a space was found */ numfit=(int)(ce-cc); } } /* alloc more space? */ if(line>=m_linelist.GetNumEntries()) m_linelist.Alloc(line<<3); lbptr=m_linelist.GetEntry(line); if(!lbptr) { lbptr=new kGUIInputLineInfo; m_linelist.SetEntry(line,lbptr); } lbptr->startindex=sindex; /* line starts at this character */ lbptr->endindex=sindex+numfit; /* line stops at this character */ /* calc size of Substring */ lbptr->ty=m_lltotalheight; GetSubSize(sindex,numfit,&lbptr->pixwidth,&lbptr->pixheight); if(!numfit) { /* how tall is a blank line, use height of last character in previous line */ if(!sindex) lbptr->pixheight=GetLineHeight(); else GetSubSize(sindex-1,1,0,&lbptr->pixheight); } m_lltotalheight+=lbptr->pixheight+2; lbptr->by=m_lltotalheight-1; if(t[sindex+numfit]==0 || t[sindex+numfit]==10) lbptr->hardbreak=true; else lbptr->hardbreak=false; ++line; sindex+=numfit; if(t[sindex]==10) ++sindex; else if(!numfit) break; }while(sindex<totalchars); m_llnum=line; return(maxw); }