10027 - Language Cardinality
Posted: Tue Mar 19, 2002 12:32 pm
I repetely testing if there is any other derivation of any frase.
It looks much better for read.
I GET WRONG ANSWER!
<font size=-1>[ This Message was edited by: ahanys on 2002-03-26 10:38 ]</font>
Code: Select all
/* @JUDGE_ID: 9072XC 10027 C++ */
#include <stdio.h>
#include <string.h>
char r[1001][2][11];
char s[1050][10000];
int main() {
char l[10000];
char *u;
int i = 0;
int poc = 1;
gets(l);
u = strtok(l, """);
sprintf(s[0],"%s",u);
while (gets(l) != NULL) {
u = strtok(l, """);
if (u == NULL) continue;
sprintf(r[i][0],"%s",u);
u = strtok(NULL, """);
u = strtok(NULL, """);
sprintf(r[i++][1],"%s",u);
}
int change = 1;
int stare = poc;
while (1) {
char *is = NULL;
if (!change) {
break;
} else {
change = 0;
}
for (int a=0; a<i; a++) // for each rule
for (int b=0; b<poc; b++) // for each word
while ((is = strstr(s[b], r[a][0])) != NULL) // for each
{
char tmp[10002] = "";
if (poc > 1000) {printf("Too many.n"); exit(0);}
{
for (int w=0; w<=is-s[b]; w++) {
if (w == is-s[b]) {
tmp[w] = '';
} else {
tmp[w] = s[b][w];
}
}
strcat(tmp, r[a][1]);
strcat(tmp, &s[b][(is-s[b])+strlen(r[a][0])]);
for (int t=0; t<=poc; t++) {
if (t == poc) {
strcpy(s[poc++], tmp);
change = 1;
break;
}
if (strcmp(s[t], tmp) == 0) break;
}
}
is = NULL;
if (stare == poc) {
break;
} else {
stare = poc;
}
}
}
printf("%in",poc);
}
It looks much better for read.

I GET WRONG ANSWER!

<font size=-1>[ This Message was edited by: ahanys on 2002-03-26 10:38 ]</font>