Page 2 of 2

Re: 10115 - Automatic Editing

Posted: Fri Jun 04, 2010 2:15 pm
by robertoflores
all,

be aware that -- contrary to what is stated in the problem description -- the program's filename & I/O are as usual: Main class, input with System.in & output with System.out.

AC-ed with Java!

10115 - Automatic Editing,why always wrong?

Posted: Tue Jul 06, 2010 6:44 am
by Ahshua
I don't know that's why always wrong,I check it over and over again,but I still didn't check out where the wrong. :(
Help me with solve it.
This is my source code:

Code: Select all

#include <stdio.h>
#include <string.h>
#define MAXN 1000
char str[MAXN]={'\0'},rules[11][82]={'\0'},replace[11][82]={'\0'};
char s1[MAXN]={'\0'},s2[MAXN]={'\0'};
int n;
void Autoedit(char *str,char *rule,char *rep)
{
     int len=strlen(str),lr=strlen(rule),k=0;
     for(int i=0;i<=len-lr;i++)
     {
        memset(s1,0,sizeof(s1));
        sprintf(s1,"%.*s",lr,str+i);
        if(!strcmp(s1,rule))
        {
           memset(s1,0,sizeof(s1));
           memset(s2,0,sizeof(s2));
           sprintf(s1,"%.*s",i,str);
           for(int j=i+lr;j<len;j++) s2[k++]=str[j];
           memset(str,0,sizeof(str));
           sprintf(str,"%.*s%s%s",strlen(s1),s1,rep,s2);
           len=strlen(str);
           k=0; i--;
        }
     }
}
int main()
{
    freopen("autoedit.in","r",stdin);
    freopen("autoedit.out","w",stdout);
    while(true)
    {
       scanf("%d\n",&n);
       if(n==0) break;
       for(int i=0;i<n;i++)
       {
          gets(rules[i]);
          gets(replace[i]);
       }
       gets(str);
       for(int i=0;i<n;i++)
          Autoedit(str,rules[i],replace[i]);
       printf("%s\n",str);
    }
    return 0;
}
Hope everyone will help me to solve it.

Re: 10115 - Automatic Editing,why always wrong?

Posted: Tue Jul 06, 2010 8:36 am
by sohel
Have you looked at the previous discussions related to this problem: http://acm.uva.es/board/viewtopic.php?f ... 15&start=0
Don't create a new thread for a problem that already exists. Make your post in an existing thread!

Re: 10115 - Automatic Editing

Posted: Tue Jul 06, 2010 8:44 am
by Ahshua
I don't know that's why always wrong,I check it over and over again,but I still didn't check out where the wrong. :(
Help me with solve it.
This is my source code:

Code: Select all

#include <stdio.h>
#include <string.h>
#define MAXN 1000
char str[MAXN]={'\0'},rules[11][82]={'\0'},replace[11][82]={'\0'};
char s1[MAXN]={'\0'},s2[MAXN]={'\0'};
int n;
void Autoedit(char *str,char *rule,char *rep)
{
     int len=strlen(str),lr=strlen(rule),k=0;
     for(int i=0;i<=len-lr;i++)
     {
        memset(s1,0,sizeof(s1));
        sprintf(s1,"%.*s",lr,str+i);
        if(!strcmp(s1,rule))
        {
           memset(s1,0,sizeof(s1));
           memset(s2,0,sizeof(s2));
           sprintf(s1,"%.*s",i,str);
           for(int j=i+lr;j<len;j++) s2[k++]=str[j];
           memset(str,0,sizeof(str));
           sprintf(str,"%.*s%s%s",strlen(s1),s1,rep,s2);
           len=strlen(str);
           k=0; i--;
        }
     }
}
int main()
{
    freopen("autoedit.in","r",stdin);
    freopen("autoedit.out","w",stdout);
    while(true)
    {
       scanf("%d\n",&n);
       if(n==0) break;
       for(int i=0;i<n;i++)
       {
          gets(rules[i]);
          gets(replace[i]);
       }
       gets(str);
       for(int i=0;i<n;i++)
          Autoedit(str,rules[i],replace[i]);
       printf("%s\n",str);
    }
    return 0;
}
Hope everyone will help me to solve it.

Re: 10115 - Automatic Editing

Posted: Sun Nov 14, 2010 6:23 am
by shababhsiddique
i am getting wrong answer...

may be there is a small mistake in my understanding...

the rules are to be checked everytime from the begining that is rule 1 right?

so how do you explain this?

5
a
n
b
k
nk
m
mmmm
i
kmkkknmkknn
am
ababababbabbbbaabbbaa



return "iam" ?

it should return "inm" if what i think is right

here are the steps in my program.


ababababbabbbbaabbbaa
nbabababbabbbbaabbbaa
nbnbababbabbbbaabbbaa
nbnbnbabbabbbbaabbbaa
nbnbnbnbbabbbbaabbbaa
nbnbnbnbbnbbbbaabbbaa
nbnbnbnbbnbbbbnabbbaa
nbnbnbnbbnbbbbnnbbbaa
nbnbnbnbbnbbbbnnbbbna
nbnbnbnbbnbbbbnnbbbnn
nbnbnbnbbnbbbbnnbbbnn
nknbnbnbbnbbbbnnbbbnn
nknbnbnbbnbbbbnnbbbnn
nknknbnbbnbbbbnnbbbnn
nknknbnbbnbbbbnnbbbnn
nknknknbbnbbbbnnbbbnn
nknknknbbnbbbbnnbbbnn
nknknknkbnbbbbnnbbbnn
nknknknkbnbbbbnnbbbnn
nknknknkknbbbbnnbbbnn
nknknknkknbbbbnnbbbnn
nknknknkknkbbbnnbbbnn
nknknknkknkbbbnnbbbnn
nknknknkknkkbbnnbbbnn
nknknknkknkkbbnnbbbnn
nknknknkknkkkbnnbbbnn
nknknknkknkkkbnnbbbnn
nknknknkknkkkknnbbbnn
nknknknkknkkkknnbbbnn
nknknknkknkkkknnkbbnn
nknknknkknkkkknnkbbnn
nknknknkknkkkknnkkbnn
nknknknkknkkkknnkkbnn
nknknknkknkkkknnkkknn
nknknknkknkkkknnkkknn
nknknknkknkkkknnkkknn
mnknknkknkkkknnkkknn
mnknknkknkkkknnkkknn
mnknknkknkkkknnkkknn
mmnknkknkkkknnkkknn
mmnknkknkkkknnkkknn
mmnknkknkkkknnkkknn
mmmnkknkkkknnkkknn
mmmnkknkkkknnkkknn
mmmnkknkkkknnkkknn
mmmmknkkkknnkkknn
mmmmknkkkknnkkknn
mmmmknkkkknnkkknn
mmmmkmkkknnkkknn
mmmmkmkkknnkkknn
mmmmkmkkknnkkknn
mmmmkmkkknmkknn
mmmmkmkkknmkknn
mmmmkmkkknmkknn
mmmmkmkkknmkknn
ikmkkknmkknn
ikmkkknmkknn
ikmkkknmkknn
ikmkkknmkknn
ikmkkknmkknn
iam
inm

Re: 10115 - Automatic Editing

Posted: Fri Jul 15, 2011 10:48 pm
by jfvs
No shababhsiddique, the 2 rule states that when you are done with one rule you are to move to the next rule and you cant use the rules used already. I had some troubles with this problem... but I'm quite sure that the WA that you guys are getting are because of the 3 rule in the problem statement.

Re: 10115 - Automatic Editing

Posted: Thu Jul 21, 2011 9:42 pm
by plamplam
I'm so steamed up over this problem :oops: :( ....A very easy problem and I got Accepted in first try. However, my code(I coded it in C) although getting a direct Accepted in cpp, always gets Runtime Error in C. Can anyone explain why this is so? What can be the reason?
An advanced thanks for helping :) Yet another one for reading this :wink:

10115 please tell me how to reduce the running times !

Posted: Wed Jun 13, 2012 11:47 am
by i see

Hi,the running time of my program exceed time limit,please tell me how to reduce the running time,thanks in advance !

code]
#include <iostream>
#include <string>
#include <fstream>
#define LOCAL
//#define fin cin
//#define fout cout
using namespace std;
int main()
{
#ifdef LOCAL
ifstream fin("in.cpp");
ofstream fout("out.cpp");
#endif
int rule_num,m;
string first[11];
string second[11];
string blank;
string edit;
bool log;
int num=1;
int j;
while(fin>>rule_num)
{
if(rule_num==0) break;
log=true;
getline(fin,blank);
for(int i=0;i<rule_num;)
if(log) {getline(fin,first);log=false;}
else {getline(fin,second);log=true;++i;}


getline(fin,edit);
for(int i=0;i<rule_num;)
{

if(edit.size()>=first.size()) {
for(j=0;j<=edit.size()-first.size();++j)
{
log=false;
for(m=0;m<first.size();++m)
if(first[m]!=edit[m+j]) {log=true;break;}

if(!log) {
edit.replace(j,first.size(),second);
i=0;
break;
}


}
if(log) ++i;
}
else ++i;
}
fout<<edit<<endl;

}

return 0;
}
[/code]

Re: 10115 please tell me how to reduce the running times !

Posted: Wed Jun 13, 2012 11:37 pm
by brianfry713
Don't read and write to a file

Re: 10115 please tell me how to reduce the running times !

Posted: Fri Jun 15, 2012 6:36 pm
by i see
thank you,i have passed !

Re: 10115 please tell me how to reduce the running times !

Posted: Fri Aug 17, 2012 9:48 pm
by Mukit Chowdhury
Cut after Accepted !!! :)

Re: 10115 please tell me how to reduce the running times !

Posted: Sat Aug 18, 2012 1:39 am
by brianfry713
Don't use a single getchar() and count on it being a newline, that won't work with trailing spaces.

Re: 10115 - Automatic Editing

Posted: Sat Aug 18, 2012 11:18 am
by Mukit Chowdhury
Cut.... :)

Re: 10115 - Automatic Editing

Posted: Mon Aug 20, 2012 10:42 pm
by brianfry713
Don't double post.

Re: 10115 please tell me how to reduce the running times !

Posted: Sun Sep 16, 2012 11:07 am
by Mukit Chowdhury
Got Accepted !!! :)