10115 - Automatic Editing

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Bug!
New poster
Posts: 24
Joined: Thu Oct 30, 2003 10:19 am

10115 - Automatic Editing

Post 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
Last edited by Bug! on Sun Feb 29, 2004 6:44 am, edited 1 time in total.

Shaka_RDR
New poster
Posts: 23
Joined: Sat Oct 04, 2003 12:12 pm
Location: in Your Heart ^^
Contact:

TLE

Post 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.....
Every person exists for another person. and that person exists for the other one. it's just the matter of existence...
May every person helps each other and creates a world full of joy...

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen »

I am also getting WA. Someone please help me to find bug in my code.
[cpp]
code deleted...
[/cpp]
Last edited by Subeen on Thu Jan 29, 2004 7:27 am, edited 1 time in total.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I use the same algorithm as Subeen and got Acc - I use only larger buffers for rules ...

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post 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:-?

thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

10115

Post 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; 
 } 

CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

Post 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
Jalal : AIUB SPARKS

thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

thanks

Post 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);
}

zaman
New poster
Posts: 8
Joined: Sun Jan 07, 2007 5:40 am
Location: dhaka

critical input needed in 10115

Post 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.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage

r2ro
New poster
Posts: 38
Joined: Thu Sep 25, 2008 9:26 am

Re: 10115 - Automatic Editing

Post 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);
}

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10115 - Automatic Editing

Post 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.
Last edited by Obaida on Wed Jul 08, 2009 8:12 pm, edited 3 times in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 10115 - Automatic Editing

Post 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
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10115 - Automatic Editing

Post 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!!
try_try_try_try_&&&_try@try.com
This may be the address of success.

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10115 - Automatic Editing

Post 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
try_try_try_try_&&&_try@try.com
This may be the address of success.

Post Reply

Return to “Volume 101 (10100-10199)”