850 - Crypt Kicker II
Moderator: Board moderators
850 - Crypt Kicker II
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]
[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]
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
Here's what I used:
and the output:
[/code]
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
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 clarifications
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...
thanks
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](./images/smilies/icon_biggrin.gif)
thanks
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
I assumed 1 and 2
Input:
Output:
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
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
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]) {
[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]) {
850: Crypt Kicker II
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.
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
-
- New poster
- Posts: 38
- Joined: Thu Dec 11, 2003 3:40 pm
- Location: Bangalore
I got WA help..
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]
[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...
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:
Output should be:
greets
tobias
ps: and check if you accept 80 chars per line though you all handle that correctly i think.
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
Code: Select all
No solution.
No solution.
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!
[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]
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]