It should be...
Posted: Wed Sep 15, 2004 9:22 pm
INPUT:
what the hell
is going on
OUTPUT:
1. Length of longest match: 0
Daniel "Naz
what the hell
is going on
OUTPUT:
1. Length of longest match: 0
Daniel "Naz
Code: Select all
12 12
12 12
this is a test
this is is a a test
76.67 67
67 67 76
asd
a s d c f
a d c
as de vfdv adas 1212 dfsf wegg 21341wd fwrf3 3ref qwe2
as de vfdv adas 1212 dfsf wegg 21341wd fwrf3 3ref qwe2
a s d
r t g
.;.;[
.;.;[
Code: Select all
1. Length of longest match: 2
2. Length of longest match: 4
3. Length of longest match: 2
4. Blank!
5. Blank!
6. Blank!
7. Length of longest match: 0
8. Length of longest match: 3
9. Length of longest match: 11
10. Length of longest match: 0
11. Length of longest match: 0
What do they mead by "non-letter printable punctuation characters". I have only considered A-Z and a-z and 0-9 as characters in the word and any other character equivalent to whitespace. Is it correct ?Blank lines and non-letter printable punctuation characters may appear.
Code: Select all
#include <stdio.h>
#include <string.h>
int strcount1=0,strcount2=0,casecount=0;
struct data
{
char str[20];
};
struct data a[600],b[600];
char x[1001],y[1001];
int d[600][600];
void makelist_1()
{
int i=0,j=0,k=0,flag=0;
while(x[i]!='\0')
{
if((x[i]>='A' && x[i]<='Z')||(x[i]>='a' && x[i]<='z') ||
(x[i]>='0' && x[i]<='9'))
{
flag=1;
a[k].str[j]=x[i];
j++;
}
else if(flag==1){
a[k].str[j]='\0';
k++;
j=0;
flag=0;
}
i++;
}
if(flag==1){
a[k].str[j]='\0';
k++;
}
strcount1=k;
}
void makelist_2()
{
int i=0,j=0,k=0,flag=0;
while(y[i]!='\0')
{
if((y[i]>='A' && y[i]<='Z')||(y[i]>='a' && y[i]<='z') ||
(y[i]>='0' && y[i]<='9'))
{
flag=1;
b[k].str[j]=y[i];
j++;
}
else if(flag==1){
b[k].str[j]='\0';
k++;
j=0;
flag=0;
}
i++;
}
if(flag==1){
b[k].str[j]='\0';
k++;
}
strcount2=k;
}
int LCS()
{
int i,j;
if(strcount1==0 || strcount2==0)return 0;
for(i=0;i<strcount1;i++)for(j=0;j<strcount1;j++)d[i][j]=0;
for(i=1;i<=strcount1;i++)for(j=1;j<=strcount2;j++)
{
if( !strcmp(a[i-1].str,b[j-1].str) ) d[i][j]=1+d[i-1][j-1];
else { if(d[i][j-1]>d[i-1][j])d[i][j]=d[i][j-1];
else d[i][j]=d[i-1][j];
}
}
return d[i-1][j-1];
}
void main()
{
int n,casecount=0;
while(1)
{
if(scanf("%[^\n]",x)==EOF)break;
scanf("%c",&n); // removing the newline after input
if(scanf("%[^\n]",y)==EOF)break;
scanf("%c",&n); // removing the newline after input
casecount++;
if( !strcmp(x,"") || !strcmp(y,"") ){
printf("%2d. Blank!\n",casecount);
continue;
}
makelist_1();
makelist_2();
n=LCS();
printf("%2d. Length of longest match: %d\n",casecount,n);
}
}
Code: Select all
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void main()
{
// #ifndef ONLINE_JUDGE
// #endif
char xl[1002], yl[1002];
char x[1002][20];
char y[1002][20];
int c[120][120] = {0};
int i, j, count = 0;
while (gets(xl) && gets(yl)) {
count++;
printf("%2d. ", count);
if (strlen(xl) == 0 || strlen(yl) == 0) {
printf("Blank!\n");
continue;
}
char *ch;
for (ch = xl; *ch; ch++)
if (!isalnum(*ch))
*ch = ' ';
for (ch = yl; *ch; ch++)
if (!isalnum(*ch))
*ch = ' ';
i = 1;
char *tok;
for (tok = strtok(xl, " "); tok; tok = strtok(NULL, " "), i++)
strcpy(x[i], tok);
int m = i - 1;
j = 1;
for (tok = strtok(yl, " "); tok; tok = strtok(NULL, " "), j++)
strcpy(y[j], tok);
int n = j - 1;
for (i = 1; i <= m; i++)
for (j = 1; j <= n; j++)
if (strcmp(x[i], y[j]) == 0)
c[i][j] = c[i - 1][j - 1] + 1;
else
if (c[i - 1][j] >= c[i][j - 1])
c[i][j] = c[i - 1][j];
else
c[i][j] = c[i][j - 1];
printf("Length of longest match: %d\n", c[m][n]);
}
}
Code: Select all
look down
Code: Select all
This is a test.
test
Hello!
The document provides late-breaking information
late breaking.
The document provides late-breaking information
breaking late document
The document provides late-breaking information
The provides document
The document provides late-breaking information
The provides information
Code: Select all
1. Length of longest match: 1
2. Blank!
3. Length of longest match: 2
4. Length of longest match: 1
5. Length of longest match: 2
6. Length of longest match: 3
Code: Select all
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define max 1001
int isblank(char *a)
{
for(char *i = a; *i; i++)
if(!isspace(*i))return 0;
return 1;
}
void clear(char *a,char *b)
{
for(char *i = a; *i; i++)
if(!isalnum(*i))*i = ' ';
for(char *i = b; *i; i++)
if(!isalnum(*i))*i = ' ';
}
int main()
{
int how = 0;
char str1[max],str2[max],word[21],word2[21];
while(gets(str1) && gets(str2))
{
if(!strlen(str1)||!strlen(str2))
{
printf("%2d. Blank!\n",++how);
continue;
}
clear(str1,str2);
int count = 0;char *i = str1, *j = str2;
while(!isblank(str1) && !isblank(str2))
{
if(!isblank(str2))sscanf(str2,"%s",&word);
while(isspace(*j))j++;
while(isalnum(*j))*j++ = ' ';
if(!isblank(str1))sscanf(str1,"%s",&word2);
while(isspace(*i))i++;
while(isalnum(*i))*i++ = ' ';
while(strcmp(word,word2) && !isblank(str1))
{
if(!isblank(str1))sscanf(str1,"%s",&word2);
while(isspace(*i))i++;
while(isalnum(*i))*i++ = ' ';
}
if(!strcmp(word,word2))count++;
}
printf("%2d. Length of longest match: %d\n",++how,count);
word[0] = word2[0] = '\0';
}
return 0;
}
Code: Select all
(5 Spaces)
hello
Code: Select all
Blank!
Code: Select all
1. Length of longest match: 0
Code: Select all
1. Blank!