Page 1 of 2

10115 - Automatic Editing

Posted: Thu Dec 11, 2003 6:49 am
by Bug!
I think my code should work :cry: , anyone can give me i/o sample?? :D
Here's my code

Code: Select all

Hopeless with this prob
Thanx before,
Regard, Andre

TLE

Posted: Tue Dec 30, 2003 8:24 pm
by Shaka_RDR
is it u AV ? so, you got WA ? i got TLE here... hope some one will be able to help us....

here is my code too :
[c]#include <stdio.h>
#include <string.h>
#include <ctype.h>

char rule[15][2][300];
int lenr[15][2];
int idxrule,maxrule;

char kalimat[300],dummy[300];

void main()
{
int lenk,lend;
int ik,ir,id;
int tk;
int idx;
char same,edit;
#ifndef ONLINE_JUDGE
freopen ("10115.in","r",stdin);
freopen ("10115.out","w",stdout);
#endif

while (scanf ("%d ",&maxrule)!=EOF)
{
if (maxrule==0) break;
for (idxrule=0;idxrule<maxrule;idxrule++)
{
gets(rule[idxrule][0]);
gets(rule[idxrule][1]);
lenr[idxrule][0]= strlen (rule [idxrule][0]);
lenr[idxrule][1]= strlen (rule [idxrule][1]);
}
gets(kalimat);
lenk=strlen (kalimat);

while (1)
{
edit=0;




for (idxrule=0;idxrule<maxrule;idxrule++)
{
same=1;
ik=0;
while (same==1)
{
lagi:

memset(dummy,0,300);
if (ik>=lenk)
{
same=0;
}

for (id=0;ik<lenk;ik++)
{
if (kalimat[ik]==rule[idxrule][0][0])
{
tk=ik;
for (ir=0;ir<lenr[idxrule][0];ir++,ik++)
{
same=0;
if (ik>=lenk)
{
break;
}

if (kalimat[ik]==rule[idxrule][0][ir])
{
same=1;
}
else
{
break;
}
}

if (same==0)
{
ik=tk+1;
for (idx=0,id=0;idx<=ik;idx++)
{
dummy[id]=kalimat[idx];
id++;
}

}
else
{
edit=1;
for (idx=0;idx<lenr[idxrule][1];idx++,id++)
{
dummy[id]=rule[idxrule][1][idx];
}
for (;ik<lenk;ik++)
{
dummy[id]=kalimat[ik];
id++;
}
strcpy (kalimat,dummy);
lenk=strlen (kalimat);
ik=0;
goto lagi;
}
}
else
{
for (idx=0,id=0;idx<=ik;idx++)
{
dummy[id]=kalimat[idx];
id++;
}


}

}
}
}

if (edit==0) break;
else ik=0;


}

printf ("%s\n",kalimat);
}
}
[/c]


help us please....... thx before.....

Posted: Wed Jan 28, 2004 12:50 pm
by Subeen
I am also getting WA. Someone please help me to find bug in my code.
[cpp]
code deleted...
[/cpp]

Posted: Wed Jan 28, 2004 2:34 pm
by Dominik Michniewski
I use the same algorithm as Subeen and got Acc - I use only larger buffers for rules ...

Best regards
DM

Posted: Thu Jan 29, 2004 7:22 am
by Subeen
thanks. I got it AC after increasing array limit. but previous size should work according to the problem.

Code: Select all

   char in[300];
   char text[300], *p1, *p2, *p3;
   char rules[11][2][100];
but when I replace the above part with the following I got AC.

Code: Select all

   char in[400];
   char text[400], *p1, *p2, *p3;
   char rules[11][2][400];
I think the judge's input data in not according to the problem statement. Or I misunderstood the problem statement:-?

10115

Posted: Wed Sep 28, 2005 10:09 pm
by thinker_bd
hi whatz wrong with my 10115 please help , code is given below

Code: Select all

#include<iostream> 
#include<string> 
#include<stdio.h> 
#define MAX_F_R 1000 
#define MAX_A 3600 


using namespace std; 


char find[MAX_F_R][MAX_F_R]; 
char replace[MAX_F_R][MAX_F_R]; 
char array[MAX_A]; 

int main() 
{ 
   int no_of_replace; 
   //freopen("10115.in","r",stdin); 
   while(1) 
   { 
      scanf("%d",&no_of_replace); 
      if(no_of_replace==0) 
      break; 
       
      memset(find,0,sizeof(find)); 
      memset(replace,0,sizeof(replace)); 
      memset(array,0,sizeof(array)); 
       
          
      getchar(); 
      int i=0; 
      int num=no_of_replace; 
       
      while(no_of_replace--) 
      { 
         gets(find[i]);    
         gets(replace[i]); 
         i++;       
      } 
       
      gets(array);       
      string s=array; 
       
      i=0; 
      while(num--) 
      { 
         string f=find[i]; 
         string r=replace[i]; 
          
         int pos=s.find(f); 
    
         while(pos!=string::npos) 
         { 
            s.replace(pos,f.length(),r); 
            pos=s.find(f,pos+1); 
         } 
      i++;       
      } 
      cout<<s<<endl; 
   } 
   return 0; 
 } 

Posted: Fri Sep 30, 2005 6:29 am
by CodeMaker
you misunderstood the problem.
here is some I/O for you. and dont ask me if they r correct or not because they r correct. 8)

input:

Code: Select all

1
ban
b
banananananana boat
0
output:

Code: Select all

ba boat

thanks

Posted: Thu Oct 06, 2005 8:42 pm
by thinker_bd
ya thanx codemaker i got my error and got accepted
my correction is followings

while(pos!=-1)
{
s.replace(pos,f.length(),r);
pos=s.find(f);
}

critical input needed in 10115

Posted: Mon Feb 05, 2007 6:29 pm
by zaman
I've got wa in this problem, but the inputs in this thread pass. Please give some more ip where it fails.Here is my code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 4000
void main(){
	int no_line, i, j, k, l, len, len1, len2, tmp;
	char rule[100][SIZE], repla_by[100][SIZE], text[SIZE], temp[SIZE], ch[SIZE];
	//freopen("G:\\input.txt","r",stdin);

	while (1 == scanf("%d",&no_line) && no_line){
		
		gets(rule[0]);
		
		for (i = 0; i < no_line; i++){
			gets(rule[i]);
			gets(repla_by[i]);
		}

		gets(text);
		
		for ( i = 0; i < no_line; i++){
			
			len = strlen(rule[i]);
			len1 = strlen(text);
			len2 = strlen(repla_by[i]);
			j = 0;
			
			
			while (len < (len1-j)){
				int i1 = 0;
				
				for ( k = j; k < (j+len); k++)
					ch[i1++] = text[k];
				ch[i1] = '\0';

				if (!strcmp(ch,rule[i])){
					//temp = (char*)malloc(260*sizeof(char));

					for ( k = 0; k < j; k++)
						temp[k] = text[k];
					
					if (repla_by[i][0] == '\0')
						l = j + len;
					
					
					else{
						
						tmp = j;
						for (l = 0; l < len2; l++)
							temp[j++] = repla_by[i][l];
						if (len < len2)
							l = tmp + len; 
						else if(len > len2)
							l = j + len - len2;
						else
							l = j;
					
					}
					for ( ; l <= len1; l++)
						temp[j++] = text[l];
					
					strcpy(text,temp);
					j = 0;
					len1 = strlen(text);
				}
				else
					j++;
				
			}
			

		}
		puts(text);
	}

}  
Please reply soon.

Posted: Wed Oct 17, 2007 2:02 am
by Jan
Try the cases...

Input:

Code: Select all

5
a
n
b
k
nk
m
mmmm
i
kmkkknmkknn
 am
ababababbabbbbaabbbaa
4
p
a
q
j
x
n
aaa
a
qpppppppppppppppppppppppx
0
Output:

Code: Select all

i am
jan
Hope these help.

Re: 10115 - Automatic Editing

Posted: Thu Sep 25, 2008 9:32 am
by r2ro
Hmmm...I don't understand why this code gives me WA...Any ideas?

Code: Select all

#include <iostream>
#include <stdio.h>
#include <string.h>

typedef char String[400];
using namespace std;

typedef struct
{
        int nCount;
        String str[11];
        String rule[11];
        String st;
} RulePhase;

void editStrings(String st,String targ,String rule)
{
     int i = 0,j,k,l,nCount;
     String ss,newString;
     if (strcmp(st,targ) == 0)
        strcpy(newString,rule);
     else
     {
     while (i < strlen(st))
     {
           if (strlen(st)-i < strlen(targ))
              break;
         nCount = 0;
         for (j = i;j < i+strlen(targ);j++)
         {
             ss[nCount] = st[j];
             nCount++;
             if (nCount == strlen(st))
                break;
         }
         ss[nCount] = '\0';
         if (strcmp(ss,targ) == 0)
         {
             k = 0;
             while (k < i)
             {
                   newString[k] = st[k];
                   k++;
             }
             l = 0;
             while (l < strlen(rule))
             {
                   newString[k] = rule[l];
                   k++;
                   l++;
             }
             for (l = j;l < strlen(st);l++)
             {
                 newString[k] = st[l];
                 k++;
             }
             newString[k] = '\0';
             strcpy(st,newString);
             i = 0;
         }
         else
             i++;
     }
     }
     strcpy(st,newString);
}

int main()
{
    int nNum,i,j,nIn = 0;
    char cDump;
    String str[11];
    String rule[11]; 
    String st;
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);
    do
    {
        scanf("%d%c",&nNum,&cDump);
        if (nNum > 0)
        {
                 for (i = 0;i < nNum;i++)
                 {
                     gets(str[i]);
                     gets(rule[i]);
                 }
                 gets(st);
                for (i = 0;i < nNum;i++)
                     editStrings(st,str[i],rule[i]);
                 printf("%s\n",st);
                 nIn++;
        }
    } while (nNum > 0);
}

Re: 10115 - Automatic Editing

Posted: Mon Jul 06, 2009 1:59 am
by Obaida
I didn't have any idea why my code get's wa? :(
so need to wait for help.. any one plz check my code..

Code: Select all

#include<stdio.h>
#include<string.h>
char m[11][81],temp[256];
int len[11],n;
int cmp(int a,int l)
{
	int c;
	bool eq=1;
	if(len[l]==a)
	{
		for(c=0;c<len[l];c++){if(m[l][c]!=temp[c]){eq=0;break;}}
		if(eq)return 1;
	}
	return 0;
}
int main()
{
	char st[256],r[11][81];
	int i,j,len_r[11],len_st,b,k,l;
	int eq,t_eq;
	while(scanf("%d",&n)==1&&n!=0)
	{
		for(i=0;i<n;i++)
		{
			while(1){gets(m[i]);if(m[i][0]!=0)break;}
			while(1){gets(r[i]);if(r[i][0]!=0)break;}
			len[i]=strlen(m[i]);
			len_r[i]=strlen(r[i]);
		}
		while(1){gets(st);if(st[0]!=0)break;}
		len_st = strlen(st);
		for(l=0;l<n;l++)
		{
			while(1)
			{
			eq=0;t_eq=0;
			for(i=0;i<len_st;i++)
			{
				k=0;
				for(j=i;j<len_st;j++)
				{
					temp[k++]=st[j];
					eq = cmp(k,l);
					if(eq)
					{
						b=0;
						strcpy(temp,st);
						for(k=i;k<len_r[l]+i;k++)st[k]=r[l][b++];
						for(b=j+1;b<len_st;b++)st[k++]=temp[b];
						len_st = k;i=0;j=0;t_eq=1;k=0;
					}
				}
			}
			if(!t_eq)break;
			}
		}
		for(i=0;i<len_st;i++)printf("%c",st[i]);
		puts("");
	}
	return 0;
}
And
can any one explain this output of
jan
INPUT:

Code: Select all

5
a
n
b
k
nk
m
mmmm
i
kmkkknmkknn
am
ababababbabbbbaabbbaa
4
p
a
q
j
x
n
aaa
a
qpppppppppppppppppppppppx
0
OUTPUT:

Code: Select all

i am
jan
But i think it will be :

Code: Select all

iam
jan
some one tell me if i am wrong? N help me to get Acc.

Re: 10115 - Automatic Editing

Posted: Mon Jul 06, 2009 6:28 pm
by kbr_iut
input

Code: Select all

5
a
n
b
k
nk
m
mmmm
i
kmkkknmkknn
am
ababababbabbbbaabbbaa
4
p
a
q
j
x
n
aaa
a
qpppppppppppppppppppppppx
0
my AC code gives

Code: Select all

iam
jan

Obaida wrote
can any one explain this output of

Code: Select all

jan
here r the steps.
1)replace all p with a
qpppppppppppppppppppppppx -> qaaaaaaaaaaaaaaaaaaaaaaax
2)replace aaa with a each time
qaaaaaaaaaaaaaaaaaaaaaaax -> qax
3)replace q with j
qax -> jax
4)replace x with n -> jan

remember one thing...whenever u replace something with something...u have to search to find it again.
suppose we have to replace aaa with a from aaaaaaa
then what will happen.
aaaaaaa=aaaaa
aaaaa=aaa
aaa=a

so our result is a
hope it will help

Re: 10115 - Automatic Editing

Posted: Mon Jul 06, 2009 7:01 pm
by Obaida
i was confused about
i am
or
iam
from my point i think it should be "iam"
by the way m still wa!!

Re: 10115 - Automatic Editing

Posted: Sat Jul 11, 2009 1:30 am
by Obaida
I got Acc :)
Just re-write my code by replacing the manual part with functions.

and my previous posted case is right...
Correct answer is:

Code: Select all

iam
jan