865 - Substitution Cypher
Moderator: Board moderators
865 - Substitution Cypher
can anybody tell me where is the mistake in my program or
give me some inputs and outputs of an AC program
Here is my code
[pascal]
var i,j,k,l,n,m,p,r:integer;
a:array[#1..#255] of char;
c:array[#1..#255] of boolean;
s,t:string;
begin
readln(p);
readln;
for r:=1 to p do
begin
fillchar(a,sizeof(a),' ');
fillchar(c,sizeof(c),false);
readln(s);
readln(t);
writeln(t);
writeln(s);
l:=length(t);
for i:=1 to l do
begin
if s<>' ' then
a[s]:=t;
c[s]:=true;
end;
while not(eoln) do
begin
readln(s); l:=length(s);
for i:=1 to l do
if c[s] then write(a[s]) else write(s);
writeln;
end;
if r<>p then writeln;
end;
end.
[/pascal]
plz help me
give me some inputs and outputs of an AC program
Here is my code
[pascal]
var i,j,k,l,n,m,p,r:integer;
a:array[#1..#255] of char;
c:array[#1..#255] of boolean;
s,t:string;
begin
readln(p);
readln;
for r:=1 to p do
begin
fillchar(a,sizeof(a),' ');
fillchar(c,sizeof(c),false);
readln(s);
readln(t);
writeln(t);
writeln(s);
l:=length(t);
for i:=1 to l do
begin
if s<>' ' then
a[s]:=t;
c[s]:=true;
end;
while not(eoln) do
begin
readln(s); l:=length(s);
for i:=1 to l do
if c[s] then write(a[s]) else write(s);
writeln;
end;
if r<>p then writeln;
end;
end.
[/pascal]
plz help me
Try the input / output that is below.
Please have in mind several things:
1) The first input text contains two lines
which seem like empty lines. That is why they
contain just spaces. Put in each of these
line 2-3 spaces. This may reveal a BUG in your
program like it did reveal one in mine.
2) In the second input the plaintext alphabet it:
aeoiu<space>. And the substitution
alphabet is AEOIUX so each space gets
substituted with an X.
3) Note also that my program gets Accepted P.E.
and not a clean Accepted. I normally do not work
more on a problem after I get Accepted P.E. I am
not a real contester, quite old for that
INPUT
OUTPUT
Please have in mind several things:
1) The first input text contains two lines
which seem like empty lines. That is why they
contain just spaces. Put in each of these
line 2-3 spaces. This may reveal a BUG in your
program like it did reveal one in mine.
2) In the second input the plaintext alphabet it:
aeoiu<space>. And the substitution
alphabet is AEOIUX so each space gets
substituted with an X.
3) Note also that my program gets Accepted P.E.
and not a clean Accepted. I normally do not work
more on a problem after I get Accepted P.E. I am
not a real contester, quite old for that
![;)](./images/smilies/icon_wink.gif)
INPUT
Code: Select all
2
abcdefghijklmnopqrstuvwxyz
zyxwvutsrqponmlkjihgfedcba
Shar's Birthday:
The birthday is October 6th, but the party will be Saturday,
October 5. It's my 24th birthday and the first one in some
years for which I've been employed. Plus, I have new clothes.
So I have cause to celebrate. More importantly, though,
we've cleaned the house! The address is 506-D Albert Street.
Extra enticement for CS geeks: there are several systems in
the house, and the party is conveniently scheduled for 3 hours
after the second CSC programming contest ends (not to mention,
within easy walking distance)!
aeoiu
AEOIUX
For each test case, the output must follow the description
below. The outputs of two consecutive cases will be
separated by a blank line.
Code: Select all
zyxwvutsrqponmlkjihgfedcba
abcdefghijklmnopqrstuvwxyz
Sszi'h Brigswzb:
Tsv yrigswzb rh Oxglyvi 6gs, yfg gsv kzigb droo yv Szgfiwzb,
Oxglyvi 5. Ig'h nb 24gs yrigswzb zmw gsv urihg lmv rm hlnv
bvzih uli dsrxs I'ev yvvm vnkolbvw. Pofh, I szev mvd xolgsvh.
Sl I szev xzfhv gl xvovyizgv. Mliv rnkligzmgob, gslfts,
dv'ev xovzmvw gsv slfhv! Tsv zwwivhh rh 506-D Aoyvig Sgivvg.
Ecgiz vmgrxvnvmg uli CS tvvph: gsviv ziv hvevizo hbhgvnh rm
gsv slfhv, zmw gsv kzigb rh xlmevmrvmgob hxsvwfovw uli 3 slfih
zugvi gsv hvxlmw CSC kiltiznnrmt xlmgvhg vmwh (mlg gl nvmgrlm,
drgsrm vzhb dzoprmt wrhgzmxv)!
AEOIUX
aeoiu
FOrXEAchXtEstXcAsE,XthEXOUtpUtXmUstXfOllOwXthEXdEscrIptIOn
bElOw.XThEXOUtpUtsXOfXtwOXcOnsEcUtIvEXcAsEsXwIllXbE
sEpArAtEdXbyXAXblAnkXlInE.
Pleasssssse help me on this problem.I am getting a lot of wa.
My code is given below:
Please help me to find the errors or give some sample i/o.
My code is given below:
Code: Select all
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
//#define Long __int64
//#define Long long long
int main()
{
int n,i,flag=1,j,printed=0;
char alpha[30],plain[30],c;
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(i)printf("\n");
scanf("%s%s",alpha,plain);
scanf("%c",&c);
printf("%s\n%s\n",plain,alpha);
while((c=getchar())!=EOF)
{
printed=0;
if(c=='\n')
{
if(!flag)
{
printed=flag=1;
break;
}
else
{
flag=0;
printf("%c",c);
printed=1;
}
}
else flag=1;
for(j=0;alpha[j];j++)
if(alpha[j]==c)
{
printf("%c",plain[j]);
printed=1;
}
if(!printed)printf("%c",c);
}
}
return 0;
}
Your program is confusing and hard to debug (I tried, but couldn't find the bug).Anindya wrote:Pleasssssssssseeeeeeeee help me.I am getting consecutive WA's.
Give me some sample i/o or help me to find my errors.
Thanks in advance.
How about using gets() instead of getchar() like below.
Then you don't need to do complexing things (flag, printed ..)
Code: Select all
while (gets(buf) && *buf) {
for (i = 0; buf[i]; ++i)
....;
putchar('\n');
}
Rio
-
- Learning poster
- Posts: 74
- Joined: Sat Jul 15, 2006 6:28 am
- Location: CUET , bangladesh
- Contact:
please help me.... i am getting WA in 865.
Thanks in advance.
Thanks in advance.
Code: Select all
Last edited by shakil on Wed Jun 27, 2007 10:54 am, edited 1 time in total.
SHAKIL
WRONG ANSWER
![:evil:](./images/smilies/icon_evil.gif)
Code: Select all
#include<stdio.h>
int main()
{
char plain[60],subs[60],text[70];
int n,vector[150],i,t=0;
scanf("%d",&n);
while(n--)
{
scanf(" %s %s",plain,subs);
getchar();
for(i=0;i<150;vector[i]=i,i++);
for(i=0;plain[i];vector[plain[i]]=subs[i],i++);
if(t)
printf("\n");
else
t=1;
printf("%s\n%s\n",subs,plain);
while(gets(text)&&*text)
{
for(i=0;text[i];printf("%c",vector[text[i]]),i++);
printf("\n");
}
}
return 0;
}
In this problem, 'alphabet" means not only a .. z, A .. Z, but set of letters.
So there might be a case like below.
I confirm this by using assert(), which yield RE (Signal 6),
----
Rio
So there might be a case like below.
Code: Select all
1
abc,-= y89
1234567890
This is a test.
Code: Select all
for (i = 0; plain[i]; ++i)
assert(isalpha(plain[i]) && isalpha(subs[i]));
Rio