865 - Substitution Cypher

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

Moderator: Board moderators

User avatar
GVahe
New poster
Posts: 17
Joined: Thu Aug 05, 2004 6:04 pm
Location: Armenia
Contact:

865 - Substitution Cypher

Post by GVahe » Sat Oct 23, 2004 10:42 pm

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

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » Sun Feb 13, 2005 1:57 pm

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

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

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.

User avatar
GVahe
New poster
Posts: 17
Joined: Thu Aug 05, 2004 6:04 pm
Location: Armenia
Contact:

Post by GVahe » Mon Feb 14, 2005 7:42 pm

thanks, I get ACC :)
I think I was very tired when I was writing that program (so stupid mistake :( )

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

ACC

Post by Sedefcho » Mon Feb 14, 2005 8:21 pm

Did you get ACC using my sample I/O?!

Your previoud POST is from Oct 23, 2004

I didn't believe you will read my post !!!

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » Mon Feb 14, 2005 8:22 pm

Your PREVIOUS POST[color], I meant
is from Oct 23, 2004 [color] ?!

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » Mon Feb 14, 2005 8:22 pm

Your PREVIOUS POST, I meant
is from Oct 23, 2004 ?!

User avatar
GVahe
New poster
Posts: 17
Joined: Thu Aug 05, 2004 6:04 pm
Location: Armenia
Contact:

Post by GVahe » Mon Feb 14, 2005 9:20 pm

I don't see this problem after I that post, so when u reply I read it again, open my program and find the bug using your I/O.

P.S. maybe you get PE because ur program prints a line after last case.

Anindya
New poster
Posts: 28
Joined: Sun Feb 04, 2007 4:34 am
Location: EEE,BUET,DHAKA

865-WA!

Post by Anindya » Sun Feb 04, 2007 6:11 am

I am getting Wa on 865.
Can anyone give me some sample i/o?

Anindya
New poster
Posts: 28
Joined: Sun Feb 04, 2007 4:34 am
Location: EEE,BUET,DHAKA

Post by Anindya » Wed Feb 07, 2007 6:07 am

Pleasssssse help me on this problem.I am getting a lot of wa.
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;
}
Please help me to find the errors or give some sample i/o.

Anindya
New poster
Posts: 28
Joined: Sun Feb 04, 2007 4:34 am
Location: EEE,BUET,DHAKA

Post by Anindya » Sun Feb 18, 2007 12:54 pm

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.

shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

WA 865

Post by shakil » Sun Jun 24, 2007 7:44 pm

i also get WA. But why?? can any one give some sample input and output???
SHAKIL

User avatar
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio » Mon Jun 25, 2007 9:06 am

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.
Your program is confusing and hard to debug (I tried, but couldn't find the bug).
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

shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

Post by shakil » Tue Jun 26, 2007 8:42 am

please help me.... i am getting WA in 865.
Thanks in advance.
Last edited by shakil on Wed Jun 27, 2007 10:54 am, edited 1 time in total.
SHAKIL

abhiramn
New poster
Posts: 29
Joined: Sat May 26, 2007 7:54 pm

Post by abhiramn » Tue Jun 26, 2007 2:38 pm

WRONG ANSWER :evil:

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

User avatar
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio » Wed Jun 27, 2007 3:09 am

In this problem, 'alphabet" means not only a .. z, A .. Z, but set of letters.
So there might be a case like below.

Code: Select all

1

abc,-= y89
1234567890
This is a test.
I confirm this by using assert(), which yield RE (Signal 6),

Code: Select all

for (i = 0; plain[i]; ++i)                                                              
   assert(isalpha(plain[i]) && isalpha(subs[i]));
----
Rio

Post Reply

Return to “Volume 8 (800-899)”