850 - Crypt Kicker II

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

_Andrey_
New poster
Posts: 2
Joined: Mon Feb 10, 2003 8:06 pm

850 - Crypt Kicker II

Post by _Andrey_ »

I will be VERY GRATEFUL if anyone helps me with this Wrong Answer:
[c]#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>


char mas[100][81];
char cryptstring[44],cryptlike[27];

int is_code_str(int snum)
{
int j;
char len;
for(j=0;j<26;j++) cryptlike[j]='0';
len=strlen(mas[snum]);
if (len!=43) return 0;
for (j=0;j<len;j++)
{
if ( (mas[snum][j]==32) ^ (32==cryptstring[j]) ) return 0;
else if (mas[snum][j]==32) continue;
if (cryptlike[mas[snum][j]-'a']==48)
cryptlike[mas[snum][j]-'a']=cryptstring[j];
else if (cryptlike[mas[snum][j]-'a']!=cryptstring[j]) return 0;
}
for (j=0;j<26;j++)
if (cryptlike[j]==48) return 0;
return 1;
}

void decode(int snum)
{
int k,l,m;
for (l=0;l<=snum;l++)
{
k=strlen(mas[l]);
for (m=0;m<k;m++)
{
mas[l][m]=cryptlike[mas[l][m]-'a'];
}
printf("%s\n",mas[l]);
}
}


int main()
{
int flag,next,i,strnum,number;
int g;
int iterator;
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
strcpy(cryptstring,"the quick brown fox jumps over the lazy dog");
scanf("%u%*c%*c",&number);
cryptlike[26]='\0';
for (iterator=1;iterator<=number;iterator++)
{
for(i=0;i<=99;i++) mas[0]='\0';
strnum=0;
flag=0;
while (gets(mas[strnum])!=NULL)
{
if (strlen(mas[strnum])==0)
{
if (!flag) printf("No solution.\n\n");
else
{
decode(strnum-1);
printf("\n");
}
break;
}
if (!flag)
if (is_code_str(strnum)) flag=1;
strnum++;
}
}
if (!flag) printf("No solution.");
else decode(strnum-1);
return 0;
}[/c]

User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo »

My algorithm is almost the same as yours. I also got wrong answers. Can anybody give me some sample inputs. Thanks in advance.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Here's what I used:

Code: Select all

4

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
aaa aaaaa aaaaa aaa aaaaa aaaa aaa aaaa aaa
nm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
nm ceuob lrtzv ita hegfd tsmr xnm ypwq kjx
frtjrpgguvj otvxmdxd prm iev prmvx xnmq

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
frtjrpgguvj otvxmdxd prm iev prmvx xnmq
awerwaerwrwa

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
frtjrpgguvj otvxmdxd prm iev prmvx xnmq

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
eee eeeee lrtzv ita hegfd tsmr xnm ypwq ktj
frtjrpgguvj otvxmdxd prm iev prmvx xnmq
and the output:

Code: Select all

No solution.

now is the time for all good men to come to the aid of the party
the quick brown fox jumps over the lazy dog
programming contests are fun arent they
xzurzxurzrzx

now is the time for all good men to come to the aid of the party 
the quick brown fox jumps over the lazy dog
programming contests are fun arent they 

No solution.
[/code]

_Andrey_
New poster
Posts: 2
Joined: Mon Feb 10, 2003 8:06 pm

Post by _Andrey_ »

The sample output didn't help. Can anyone suggest a piece of advice?

nicopadu
New poster
Posts: 4
Joined: Wed Sep 18, 2002 2:16 am

850 clarifications

Post by nicopadu »

I've been dealing with this problem and I have several questions. i hope that anyone can help me with this stuff.

1- ALWAYS the key string is 43 characters length? Or it can contain more than 43? (ex: more than ONE space between two words of the valid key string)

2- spaces are char(32) or they can be another thing?

3- if you can post some cool test cases that can help me... i'll be very very happy... :D

thanks

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

I assumed 1 and 2

Input:

Code: Select all

4

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
aaa aaaaa aaaaa aaa aaaaa aaaa aaa aaaa aaa
nm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
nm ceuob lrtzv ita hegfd tsmr xnm ypwq kjx
frtjrpgguvj otvxmdxd prm iev prmvx xnmq

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
frtjrpgguvj otvxmdxd prm iev prmvx xnmq
awerwaerwrwa

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
frtjrpgguvj otvxmdxd prm iev prmvx xnmq

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
eee eeeee lrtzv ita hegfd tsmr xnm ypwq ktj
frtjrpgguvj otvxmdxd prm iev prmvx xnmq
Output:

Code: Select all

No solution.

now is the time for all good men to come to the aid of the party
the quick brown fox jumps over the lazy dog
programming contests are fun arent they
xzurzxurzrzx

now is the time for all good men to come to the aid of the party 
the quick brown fox jumps over the lazy dog
programming contests are fun arent they 

No solution.

reiners
New poster
Posts: 9
Joined: Fri May 30, 2003 6:50 pm
Location: San Francisco

850: Crypt Kicker II

Post by reiners »

I'm getting WA for my submission below, but cannot find the error. Could someone please give me an input for which my submission fails and the expected output for that input?

[cpp]
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>

using namespace std;

bool getCipher(vector<string> cipherTextLines, char cipher[26]) {

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

I do a linear search, trying to match it to the key string, and after that, I translate the line using the mapping..

reiners
New poster
Posts: 9
Joined: Fri May 30, 2003 6:50 pm
Location: San Francisco

850: Crypt Kicker II

Post by reiners »

What I'm really hoping to find is not a technique for solving the problem, but an input for which my submission fails and the expected result for that input.

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

Post by Dominik Michniewski »

Never mind - I found my mistake :)

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)

BiK
Experienced poster
Posts: 104
Joined: Tue Sep 23, 2003 5:49 pm

Post by BiK »

The judges input data for this problem are incorrect. There are input lines with length greater than 80. When I changed this constant to 93 my program was accepted.

Enjoy.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

My array size is 85, and got AC, so maybe there's one or two junk character in the end..

aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

I got WA help..

Post by aakash_mandhar »

I got WA help..
[cpp]
/* @JUDGE_ID: xxxxxxxx 850 C++ "No special algo:)" */

# include<stdio.h>
# include<string.h>

char ori[85]="the quick brown fox jumps over the lazy dog";
char sub[26]={0};
int i,done;
char count;
char a[100][85];

int main()
{
int nt;
scanf("%d",&nt);
fflush(stdin);
gets(a[count]);
fflush(stdin);
gets(a[count]);

while(nt--)
{
count=0;
done=0;
for(i=0;i<26;i++) sub=0;

while(1)
{
fflush(stdin);
gets(a[count]);
if(strcmp(a[count],"")==0) break;

if(done==0 && strlen(a[count])==strlen(ori))
{
for(i=0;i<strlen(a[count]);i++)
{
if(a[count]>='a' && a[count]<='z')
{
if(sub[a[count]-'a']==0 || sub[a[count]-'a']==ori) sub[a[count]-'a']=ori;
else break;
}
else if(a[count]!=ori) break;

}
if(i==strlen(a[count]))
{done=1;
for(i=0;i<26;i++) if(sub[i]==0) {done=0;break;}
}

}
count++;
}
if(done==0)
{
printf("No solution.\n");
}
else
{
for(i=0;i<count;i++)
{
for(int j=0;j<strlen(a[i]);j++)
{
if(a[i][j]>='a' && a[i][j]<='z') printf("%c",sub[a[i][j]-'a']);
else printf("%c",a[i][j]);
}
printf("\n");
}
}
if(nt) printf("\n");
}
return 1;
}


//@end_of_source_code

[/cpp]
...I was born to code...

macin
New poster
Posts: 6
Joined: Tue Apr 06, 2004 6:40 pm

Post by macin »

im too lazy to look into your parsing routines but do you handle cases with 100 lines correctly? try a buffer for 101 lines or use a input with 100 lines followed by another case like the following:

Code: Select all

2

line one
line two
...
line nightynine
line hundred

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq vtz ud xnm xugm
xnm ceuob lrtzv ita heefd tsmr xnm ypwq ktj
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq kt
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktjsdf
frtjrpgguvj otvxmdxd prm iev prmvx xnmq
Output should be:

Code: Select all

No solution.

No solution.
greets
tobias

ps: and check if you accept 80 chars per line though you all handle that correctly i think.

frankhuhu
New poster
Posts: 30
Joined: Tue Jul 20, 2004 5:22 am
Contact:

850 Who can help me? Thanks!

Post by frankhuhu »

[cpp]
Here is my code! WA! I don't know why.

#include <iostream.h>
#include <string.h>
#include <cctype>
#include <stdio.h>

char sample1[]="xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj";

void change(char *chst);

int main()
{
char p[200][200];
char string[100];
change(string);
int i,t;
cin>>t;
scanf("\n");
for (i=0;i<t;i++)
{
int num=0,j,k;
bool flag=false;
while (1)
{
cin.getline(p[num],100);
if (strcmp( p[num],"\0" )==0) break;
num++;
}
for (j=0;j<num;j++)
{
if (strcmp(p[j],sample1)==0)
{
flag=true;break;
}
}
if (flag==false)
{
cout<<"No solution.\n"<<endl;
continue;
}
for (j=0;j<num;j++)
{
for (k=0;p[j][k]!='\0';k++)
{
if ( isalpha(p[j][k]) )
cout<<string[p[j][k]-'a'];
else cout<<' ';
}
cout<<endl;
}
cout<<endl;
}
return 0;
}

void change(char *chst)
{
chst[0]='x'; chst[1]='k'; chst[2]='q'; chst[3]='s'; chst[4]='u';
chst[5]='p'; chst[6]='m'; chst[7]='j'; chst[8]='f'; chst[9]='g';
chst[10]='d'; chst[11]='b'; chst[12]='e'; chst[13]='h'; chst[14]='c';
chst[15]='a'; chst[16]='y'; chst[17]='r'; chst[18]='v'; chst[19]='o';
chst[20]='i'; chst[21]='n'; chst[22]='z'; chst[23]='t'; chst[24]='l';
chst[25]='w';
}

[/cpp]

Post Reply

Return to “Volume 8 (800-899)”