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

robertoflores
New poster
Posts: 1
Joined: Tue Mar 08, 2005 10:46 pm

Re: 10115 - Automatic Editing

Post 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!
Ahshua
New poster
Posts: 7
Joined: Fri Jul 02, 2010 3:05 pm

10115 - Automatic Editing,why always wrong?

Post 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.
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10115 - Automatic Editing,why always wrong?

Post 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!
Ahshua
New poster
Posts: 7
Joined: Fri Jul 02, 2010 3:05 pm

Re: 10115 - Automatic Editing

Post 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.
shababhsiddique
New poster
Posts: 2
Joined: Sun Nov 14, 2010 6:16 am

Re: 10115 - Automatic Editing

Post 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
jfvs
New poster
Posts: 12
Joined: Wed Feb 02, 2011 10:40 am

Re: 10115 - Automatic Editing

Post 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.
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10115 - Automatic Editing

Post 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:
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
i see
New poster
Posts: 9
Joined: Sat May 19, 2012 7:35 am

10115 please tell me how to reduce the running times !

Post 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]
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

Post by brianfry713 »

Don't read and write to a file
Check input and AC output for thousands of problems on uDebug!
i see
New poster
Posts: 9
Joined: Sat May 19, 2012 7:35 am

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

Post by i see »

thank you,i have passed !
Mukit Chowdhury
Learning poster
Posts: 99
Joined: Fri Aug 17, 2012 9:23 pm
Location: Dhaka
Contact:

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

Post by Mukit Chowdhury »

Cut after Accepted !!! :)
Last edited by Mukit Chowdhury on Sun Sep 16, 2012 11:12 am, edited 2 times in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

Post by brianfry713 »

Don't use a single getchar() and count on it being a newline, that won't work with trailing spaces.
Check input and AC output for thousands of problems on uDebug!
Mukit Chowdhury
Learning poster
Posts: 99
Joined: Fri Aug 17, 2012 9:23 pm
Location: Dhaka
Contact:

Re: 10115 - Automatic Editing

Post by Mukit Chowdhury »

Cut.... :)
Last edited by Mukit Chowdhury on Wed Sep 19, 2012 12:51 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10115 - Automatic Editing

Post by brianfry713 »

Don't double post.
Check input and AC output for thousands of problems on uDebug!
Mukit Chowdhury
Learning poster
Posts: 99
Joined: Fri Aug 17, 2012 9:23 pm
Location: Dhaka
Contact:

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

Post by Mukit Chowdhury »

Got Accepted !!! :)
Post Reply

Return to “Volume 101 (10100-10199)”