Page 1 of 6

850 - Crypt Kicker II

Posted: Mon Feb 10, 2003 8:19 pm
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]

Posted: Tue Feb 11, 2003 3:03 am
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.

Posted: Tue Feb 11, 2003 10:46 am
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]

Posted: Sat Feb 22, 2003 3:49 pm
by _Andrey_
The sample output didn't help. Can anyone suggest a piece of advice?

850 clarifications

Posted: Wed Aug 06, 2003 12:26 am
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

Posted: Wed Aug 06, 2003 3:12 am
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.

850: Crypt Kicker II

Posted: Sat Sep 13, 2003 11:39 pm
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]) {

Posted: Sun Sep 14, 2003 10:40 am
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..

850: Crypt Kicker II

Posted: Mon Sep 15, 2003 12:01 am
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.

Posted: Mon Oct 06, 2003 2:57 pm
by Dominik Michniewski
Never mind - I found my mistake :)

Best regards
DM

Posted: Mon Oct 20, 2003 6:03 pm
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.

Posted: Tue Oct 21, 2003 7:08 pm
by Larry
My array size is 85, and got AC, so maybe there's one or two junk character in the end..

I got WA help..

Posted: Tue Dec 30, 2003 8:00 am
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]

Posted: Thu Apr 08, 2004 2:59 pm
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.

850 Who can help me? Thanks!

Posted: Wed Oct 06, 2004 5:20 pm
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]