int main(){ for( int i = 0; i < 1001; ++i ) pd[ i ][ 0 ] = pd[ 0 ][ 1 ] = 0; while( gets( s1 ) ){ gets( s2 ); tam1 = strlen( s1 ); tam2 = strlen( s2 ); printf( "%d\n", lcs() ); } }
/* Driver program to test above function */ int main() { char X[] = "AGGTAB"; char Y[] = "GXTXAYB"; int m = strlen(X); int n = strlen(Y); printf("Length of LCS is %d\n", lcs( X, Y, m, n ) ); return 0; }
int main() { int len1,len2; while(scanf("%s",s1)!=EOF&&scanf("%s",s2)!=EOF) { len1=strlen(s1); len2=strlen(s2); memset(dp,-1,sizeof dp); printf("%d",lcs(len1,len2)); } return 0; }
char * bestmatch(char * text){ int best_bledy=666; int best=-1; for(int i=0;i<ILOSC_SLOW;i++){ int bledy= strlen(slownik[i]) + strlen(text) - lcs(text, slownik[i])*2; if(bledy< best_bledy){ best_bledy=bledy; best=i; } } return slownik[best]; }
int main() { char A[100], B[100]; printf("Enter two strings: \n First string: "); gets(A); printf("\nSecond string: "); gets(B); printf("The longest commong subsequence is of length %d ",lcs(A,B)); return(0); }
int main(int argc, char const *argv[]) { char a[5000]; char b[5000]; scanf("%s%s",a,b); char * output = lcs(a,b); fprintf(stderr,"%s",output); if(output == NULL) printf("%d",0); else printf("%d",strlen(output)); return 0; }
int main(){ int P[] = {1,2,3,4}; int T[] = {2,3}; int m, n; n = sizeof(P) / sizeof(int); m = sizeof(T) / sizeof(int); printf("lcs = %d\n", lcs(P, T, n , m)); return 0; }
int lcs(char *x,char *y,int m,int n) { char *l=(char*)malloc(sizeof(char)*m); if(m==0||n==0) { return 0; } if( x[m-1]== y[n-1]) { return 1+lcs(x,y,m-1,n-1); } else { return max(lcs(x,y,m,n-1),lcs(x,y,m-1,n)); } }
int main() { long int a,b; scanf("%s",x); scanf("%s",y); a=strlen(x); b=strlen(y); memset(dp,-1,sizeof dp); printf("%ld",lcs(a,b)); return 0; }
/*match degree,a simple function. (I think it is awkward. But I can't find a better one. Hope you have a better idea.) */ int match(char *ci_query,char *match_name) { int i,j,retval; case_insen_trans(lcs_buf,match_name); retval=lcs(ci_query,lcs_buf,&i,&j); nplaces=0; while(i!=0 || j!=0){ occur_place[nplaces++]=j; i=from[i][j][0]; j=from[i][j][1]; } return retval*bignum+bignum-discrete_fact(); }
int main() { long i,kas=1; while(scanf("%ld %ld",&m,&n)==2&&m&&n) { for(i=0;i<m;i++) scanf("%ld",&s1[i]); for(i=0;i<n;i++) scanf("%ld",&s2[i]); printf("Twin Towers #%ld\nNumber of Tiles : ",kas++); lcs(); } return 0; }
int main(void) { int n; int correct[MAXN], test[MAXN]; scanf("%d", &n); input(correct, n); while (input(test, n)) { lcs(correct, test, n); printf("%d\n", list[n][n]); } return 0; }
int main() { int size1, size2; while(1) { scanf("%d%d", &size1, &size2); char *input1 = new char[size1]; char *input2 = new char[size2]; scanf("%s", input1); scanf("%s", input2); printf("Answer = %d.\n\n", lcs(input1, input2, size1, size2)); } return 0; }
int main(void) { size_t i,j; diff *d; d = lcs(x, y); print_diff(d, x, y); for(i = 0; i <= (d->m); i++) { putchar('\n'); for(j = 0; j < d->n; j++) printf("%d ", d->c[i*d->n+j]); } putchar('\n'); return 0; }
int main(int argc, char *argv[]){ if (argc == 3){ // Nome do arquivo (argv[0]) mais os dois parâmetros char entrada[40] = "entrada/"; char saida[40] = "saida/"; int k; // Instâncias de palavras char *palavra; palavra = (char *) malloc (MAXCHAR * sizeof(char)); int tamPalavra; Matriz estados; // Matriz n x 2, onde n é o tamanho da string e possui dois estados, o atual e o anterior. strcat(entrada,argv[1]); strcat(saida,argv[2]); FILE * inp = abreArquivoLeitura(entrada); FILE * out = abreArquivoEscrita(saida); fscanf(inp, "%d ", &k); // Lê as k instâncias de problemas for (int l=0; l<k; l++){ fscanf(inp,"%s\n",palavra); tamPalavra = strlen(palavra); criaMatriz(2,tamPalavra+1,&estados); preencheMatriz(0,&estados); // Preenche matriz toda com 0 fprintf(out,"%d\n",lcs(palavra, tamPalavra, &estados)); //imprimeMatriz(estados); destroiMatriz(&estados); } free(palavra); fechaArquivo(inp); fechaArquivo(out); } else{ printf("Número incorreto de parâmetros. Fazer seguir exemplo:\n\n\t./tp2 input.txt output.txt\n\n"); exit(0); } return 0; }
int main() { register int i=0; A[i]=getchar_unlocked(); while(A[i]!='\n') A[++i]=getchar_unlocked(); A[i]='\0'; i=0;B[i]=getchar_unlocked(); while(B[i]!='\n') B[++i]=getchar_unlocked(); B[i]='\0'; lcs(); return 0; }
int main(void) { scanf("%d", &N); get(ans1); while (1) { get(ans2); if (feof(stdin)) break; lcs(); } return 0; }
int main() { int t,i,j,k; int temp; int max; scanf("%d",&t); while(t--) { max=0; i=0; j=0; while(1) { scanf("%d",&temp); if(temp==0) break; src[i++]=temp; } while(1) { scanf("%d",&temp); if(temp==0) { break; } else { j=0; comp[j++]=temp; while(1) { scanf("%d",&temp); if(temp==0) break; comp[j++]=temp; } int res=lcs(i,j); if(res>max) max=res; } } printf("%d\n",max); } return 0; }
int main() { int t1; scanf("%d",&t1); while(t1--) { scanf("%s%s",s,t); lcs(s,t,u); int s1=strlen(s); int u1=strlen(u); if(s1==u1) printf("0\n"); else printf("%d\n",strlen(s)-strlen(u)); } return 0; }
int main() { int t; scanf("%d",&t); while(t--) { int i,j; for(i=0;i<6000;i++) for(j=0;j<6000;j++) dp[i][j] = -1; scanf("%s",x); int n = strlen(x); rev(y,x); printf("%d\n",n - lcs(n-1,n-1)); } return 0; }
int main() { char s1[100],s2[100]; int i=0; scanf("%s",s1); scanf("%s",s2); struct result res; res=lcs(s1,s2); printf("\nThe length of LCSusbstring is %d and the end index is %d-->",res.len,res.end_index); i=res.end_index-res.len+1; for(;i<=res.end_index;i++) { printf("%c",s2[i]); } return 0; }
int nileDiff(FILE *oldfile, FILE *newfile, FILE *output, enum Options options) { int rv = 1; off_t oldoff = 0, newoff = 0, lastSkip = 0; size_t oldsize, newsize; char *olddata = NULL, *newdata = NULL, md5sum[MD5_DIGEST_LENGTH] = { 0 }, header[8]; if((oldsize = mapfile(oldfile, &olddata)) == -1) rv = 1; else if((newsize = mapfile(newfile, &newdata)) == -1) rv = 1; fputs(MAGIC, output); // newfile: uncompress and build md5sum if((newfile = uncompress(newfile, output, options)) == NULL) goto diff_cleanup; buildhash(md5sum, newfile); fwrite(md5sum, sizeof(md5sum), 1, output); // oldfile: uncompress and build md5sum if((oldfile = uncompress(oldfile, NULL, options)) == NULL) goto diff_cleanup; buildhash(md5sum, oldfile); fwrite(md5sum, sizeof(md5sum), 1, output); // Building Diff for(oldoff = newoff = 0; oldoff < oldsize && newoff < newsize;) { if(lcs(olddata, &oldoff, oldsize, newdata, &newoff, newsize, &lastSkip, output)) break; } // write trailing diff offtout(lastSkip, header); fwrite(header, sizeof(header), 1, output); offtout(oldsize - oldoff, header); fwrite(header, sizeof(header), 1, output); offtout(newsize - newoff, header); fwrite(header, sizeof(header), 1, output); fwrite(&newdata[newoff], newsize - newoff, 1, output); diff_cleanup: if(oldsize >= 0) munmap(olddata, oldsize); if(newsize >= 0) munmap(newdata, newsize); return rv; }
int main() { memset(res, 0, sizeof(res)); scanf("%d", &N); getchar(); int i; for(i=1; i<=N; i++) scanf("%c", &str[i]); str[N+1] = '\0'; for(i=1; i<=N; i++) rev_str[i] = str[N-i+1]; rev_str[N+1] = '\0'; int ans = lcs(); printf("%d\n", (N-ans) ); return 0; }
config_struct* getConfigObject(LPCWSTR name,config_struct* obj = 0){ static ObjectList<config_struct>* dbList = 0; LocalCriticalSection lcs(_configCs); if(dbList==0){ dbList = new (mallocGlobalStaticMem(sizeof(ObjectList<config_struct>))) ObjectList<config_struct>; } if(obj!=NULL){ obj->icount--; if(obj->icount==0){ dbList->Delete(obj); } return 0; } String fn,title; if(WcsLength(name)==0){ fn = App::GetAppDirectory(); title = App::GetAppName(); FPLinkPath(fn,title); FPLinkExt(fn,L"json"); }else{ fn = name; } config_struct* rs = 0; for(uint i=0;i<dbList->Count();i++){ rs = &(*dbList)[i]; if(FPIsSame(fn,rs->FileName)){ rs->icount++; return rs; } } rs = new config_struct; rs->icount = 1; if(1!=GetFileType(fn)){ File f; f.Create(fn); } if(!rs->Tree.LoadFromFile(fn)){ CONASSERT(L"config file is not a valid json format"); } rs->FileName = fn; dbList->AddIn(rs); return rs; }
int main(int argc, char** argv){ vec* b=malloc(2*sizeof(vec)); size_t size1=1000; if(argc>1) size1 = atoi(argv[1]); size_t size2=size1 + size1/10; char* i1 = (char*) malloc(size1*sizeof(char)); char* i2 = (char*) malloc(size2*sizeof(char)); for(int i=0;i<size1;i++) i1[i]=(char)i%128; for(int i=0;i<size2;i++) i2[i]=(char)(i+10)%128; b[0].size=size1; b[0].vec = i1; b[1].size=size2; b[1].vec = i2; int64_t overhead = calc_rdtsc_overhead(); printf("Median Clock Measurement Overhead: %" PRId64 "Cycles\n",overhead); uint32_t TRIALS=100000; vec* res; measure_time(LCS,TRIALS,{res=lcs(b[0],b[1],chrcmp);for(size_t i=0;i<2;i++){vecfree(res[i]);}free(res);},overhead);
//Recursive implementation //'i' and 'j' corresponds to first string and second string position respectively int lcs(int i,int j){ if(i>n-1) return 0; if(j>m-1) return 0; if(a[i]==b[j]){ return 1+lcs(i+1,j+1); } else return 0; }
bool InterfaceElement3dTrLin :: computeGtoLRotationMatrix(FloatMatrix &answer) { // planar geometry is assumed FloatMatrix lcs(3, 3); this->computeLCS(lcs); answer.resize(18, 18); for ( int i = 0; i < 6; i++ ) { for ( int j = 1; j <= 3; j++ ) { answer.at(i * 3 + 1, i * 3 + j) = lcs.at(3, j); answer.at(i * 3 + 2, i * 3 + j) = lcs.at(1, j); answer.at(i * 3 + 3, i * 3 + j) = lcs.at(2, j); } } return 1; }
int main(int argc, char **argv) { while(1) { fcnt = scnt = 0; memset(table, 0, sizeof(table)); memset(path, 0, sizeof(path)); if(scanf("%s", first[fcnt++]) == EOF) break; while(scanf("%s", first[fcnt]) && first[fcnt][0]!='#') ++fcnt; while(scanf("%s", second[scnt]) && second[scnt][0]!='#') ++scnt; lcs(); output(fcnt, scnt); printf("\n"); } }
void main(){ int i,j; n=strlen(a); m=strlen(b); for(i=0;i<=n-1;i++){ for(j=0;j<=m-1;j++){ maxt=max(maxt,lcs(i,j)); } } printf("Longest Common Subsequence Using Recursion %d \n",maxt); lcs_DP(); printf("Longest Common Subsequence Using DP %d",imax); }
bool ExecMemory::Create(int size){ LCS lcs(_cs); if(_handle!=0) return false; _map = ::CreateFileMapping(INVALID_HANDLE_VALUE,0,PAGE_EXECUTE_READWRITE|SEC_COMMIT,0,size,0); if(_map==0){ return false; } _handle = MapViewOfFile(_map,FILE_MAP_EXECUTE|FILE_MAP_ALL_ACCESS,0,0,size); if(_handle==NULL){ CloseHandle(_map); _map = NULL; return false; } _curLarge = (char*)_handle; _curSmall = _curLarge; _setPointer(_curLarge,0,0,-HANDLE_SIZE*3); _length = size; return 1; }