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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 850 - Crypt Kicker II

Post by brianfry713 »

I ran your code with the sample input and didn't get any output.
http://ideone.com/U2yQy
Check input and AC output for thousands of problems on uDebug!
Monty
New poster
Posts: 7
Joined: Fri Feb 17, 2012 10:24 am

Re: 850 - Crypt Kicker II

Post by Monty »

I am not sure how that website works, but if you copy the code into a compiler like eclipse for example and run it, it will take input from the console and output.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 850 - Crypt Kicker II

Post by brianfry713 »

I ran it with some inputs with more than one case and it's not giving all the outputs:
http://ideone.com/NCjwN
Check input and AC output for thousands of problems on uDebug!
Monty
New poster
Posts: 7
Joined: Fri Feb 17, 2012 10:24 am

Re: 850 - Crypt Kicker II

Post by Monty »

The reason for that is because your input does not include a trailing new line. You need that in order to see if you are done with the input or typing a new line. Since we don't know how many lines there are for each input, I wait for the user to send a blank new line before terminating. Without that how else would you know? I wish it included the number of lines for each test case in it, that would simplify things. The input you tried didn't include that. The runtime error the website says is due to the system.exit I believe, because it still produces the proper output. Thanks

Edit: One of the things I just noticed was that I was trimming the input lines so I was losing leading spaces in the output. Even after fixing that I am still getting WA, hmm.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 850 - Crypt Kicker II

Post by brianfry713 »

The problem description does not say that there will be an extra blank line at the end of the input. Check for end of file.
Check input and AC output for thousands of problems on uDebug!
Monty
New poster
Posts: 7
Joined: Fri Feb 17, 2012 10:24 am

Re: 850 - Crypt Kicker II

Post by Monty »

I didn't have trouble with that in previous problems, also I am following what they did here.

http://www.programming-challenges.com/p ... e=javainfo

What character should I be looking for, for EOF? I tired '\0', that didn't work. I just need to know when the last line is finished so I can process right there without waiting for a carriage return.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 850 - Crypt Kicker II

Post by brianfry713 »

ReadLn will return null at end of file.
Check input and AC output for thousands of problems on uDebug!
helli3papa
New poster
Posts: 8
Joined: Wed Apr 11, 2012 5:48 pm

Re: 850 - Crypt Kicker II

Post by helli3papa »

HI all I got WA on this problem and this is my code :

Code: Select all

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>

#define mp make_pair
#define pb push_back
#define PII pair<int, int>
#define vi vector <int>
#define vii vector <PII>
#define sz(a) a.size()
#define ll long long

using namespace std;

string lazy = "the quick brown fox jumps over the lazy dog";

int main()
{
    int n;
    cin >> n;
    vector<string> s;
    string tmp;
    vi space_pos;
    for (int i = 0; i < sz(lazy); i++)
    {
        if(lazy[i] == '\ ')
        {
            space_pos.pb(i);
        }
    }
	getline(cin, tmp);
	getline(cin, tmp);
    for (int j = 0; j < n; j++)
    {
        int position_lazy = -1;
		int index = -1;
		s.clear();
        while(getline(cin, tmp))
        {
            if(sz(tmp) == 0)
                break;
			index++;
            //cout << tmp << endl;
            bool f = false;
            int ind = 0;
            if(sz(tmp) == sz(lazy))
            {
				int cnt = 0;
                for (int i = 0; i < sz(tmp); i++)
                {
                    if(tmp[i] == '\ ')
                    {
                        if(i == space_pos[ind])
                        {
							cnt++;
                        }
                        ind++;
                    }
                }
				if(cnt == space_pos.size())
					f = true;
				if(f && position_lazy < 0)
                {
                    position_lazy = index;
                }
            }
            else f = false;
            s.pb(tmp);
        }
        if(position_lazy < 0)
        {
			no:
            cout << "No solution." << endl;
            continue;
        }
        unsigned char how [30];
        memset(how, 255, 30);
        //cout << ":|" << endl;
        for (int i = 0; i < sz(lazy); i++)
        {
			if(lazy[i] != '\ ')
				how[s[position_lazy][i] - 'a'] = lazy[i];
        }
        for (int i = 0; i <= index; i++)
        {
            for (int j = 0; j < sz(s[i]); j++)
            {
                if(how[s[i][j] - 'a'] == 255)
                {
					goto no;
                    cout << "No solution." << endl;
                    break;
                }
                else
                {
					if(s[i][j] != '\ ')
						s[i][j] = how[s[i][j] - 'a'];
                }
            }
            cout << s[i] << endl;
        }
    }
}
what's wrong?

Thank's for your attention :)
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 850 - Crypt Kicker II

Post by brianfry713 »

The outputs of two consecutive cases will be separated by a blank line.
Check input and AC output for thousands of problems on uDebug!
helli3papa
New poster
Posts: 8
Joined: Wed Apr 11, 2012 5:48 pm

Re: 850 - Crypt Kicker II

Post by helli3papa »

Hello!

I change that and add a blank line after each out put but again ! WA

why?

Code: Select all

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>

#define mp make_pair
#define pb push_back
#define PII pair<int, int>
#define vi vector <int>
#define vii vector <PII>
#define sz(a) a.size()
#define ll long long

using namespace std;

string lazy = "the quick brown fox jumps over the lazy dog";

int main()
{
    int n;
    cin >> n;
    vector<string> s;
    string tmp;
    vi space_pos;
    for (int i = 0; i < sz(lazy); i++)
    {
        if(lazy[i] == '\ ')
        {
            space_pos.pb(i);
        }
    }
	getline(cin, tmp);
	getline(cin, tmp);
    for (int j = 0; j < n; j++)
    {
        int position_lazy = -1;
		int index = -1;
		s.clear();
        while(getline(cin, tmp))
        {
            if(sz(tmp) == 0)
                break;
			index++;
            //cout << tmp << endl;
            bool f = false;
            int ind = 0;
            if(sz(tmp) == sz(lazy))
            {
				int cnt = 0;
                for (int i = 0; i < sz(tmp); i++)
                {
                    if(tmp[i] == '\ ')
                    {
                        if(i == space_pos[ind])
                        {
							cnt++;
                        }
                        ind++;
                    }
                }
				if(cnt == space_pos.size())
					f = true;
				if(f && position_lazy < 0)
                {
                    position_lazy = index;
                }
            }
            else f = false;
            s.pb(tmp);
        }
        if(position_lazy < 0)
        {
			no:
            cout << "No solution." << endl;
            continue;
        }
        unsigned char how [30];
        memset(how, 255, 30);
        //cout << ":|" << endl;
        for (int i = 0; i < sz(lazy); i++)
        {
			if(lazy[i] != '\ ')
				how[s[position_lazy][i] - 'a'] = lazy[i];
        }
        for (int i = 0; i <= index; i++)
        {
            for (int j = 0; j < sz(s[i]); j++)
            {
                if(how[s[i][j] - 'a'] == 255)
                {
					goto no;
                    cout << "No solution." << endl;
                    break;
                }
                else
                {
					if(s[i][j] != '\ ')
						s[i][j] = how[s[i][j] - 'a'];
                }
            }
            cout << s[i] << endl;
        }
		if(j != n - 1)
			cout << endl;
    }
}
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 850 - Crypt Kicker II

Post by lighted »

BiK wrote: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.
I got accepted and my array is of length 81. One char for '/0'. So judge's input is correct. :)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 850 - Crypt Kicker II

Post by Shahidul.CSE »

I don't understand, when output should be No solution.

Can anyone explain me, when my program should print No solution.?
Thanks in advance.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 850 - Crypt Kicker II

Post by lighted »

Problem description says
Your task is to decrypt several encrypted lines of text, assuming that each line uses the same set of replacements, and that one of the lines of input is the encrypted form of the plaintext
the quick brown fox jumps over the lazy dog
When there is no line which is encrypted form of "the quick brown fox jumps over the lazy dog" you should print "No solution."
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 850 - Crypt Kicker II

Post by Shahidul.CSE »

Thanks lighted!
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 850 - Crypt Kicker II

Post by Shahidul.CSE »

I am getting WA with my code.
newkid wrote:The problem statement says..
If there is more than one possible decryption (several lines can be decoded to the key sentence), use the first line found for decoding.
Input:

Code: Select all

4

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

the quick brown fox jumps over the lazy dog

now is the time for all good men to come to the aid of the party
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
the quick brown fox jumps over the lazy dog
programming contests are fun arent they

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
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
programming contests are fun arent they
Accepted output should be:

Code: Select all

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

the quick brown fox jumps over the lazy dog

hcz fv oju ofeu pcr xbb mccs euh oc qceu oc oju xfs cp oju axrol
the quick brown fox jumps over the lazy dog
oju yifqd krczh pct gieav cnur oju bxwl scm
arcmrxeefhm qchouvov xru pih xruho ojul

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
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
programming contests are fun arent they
I didn't understand this output. And for this given case my progragram giving wrong outputs.

For above inputs, my program printing this wrong outputs:

Code: Select all

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

the quick brown fox jumps over the lazy dog

hcz fv oju ofeu pcr xbb mccs euh oc qceu oc oju xfs cp oju axrol
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
arcmrxeefhm qchouvov xru pih xruho ojul

hcz fv oju ofeu pcr xbb mccs euh oc qceu oc oju xfs cp oju axrol
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
arcmrxeefhm qchouvov xru pih xruho ojul
Actually I didn't understand how the given accepted outputs came. And I didn't understand the meaning of the problem statement
Decrypt each line and print it to standard output. If there is more than one possible decryption (several lines can be decoded to the key sentence), use the first line found for decoding.
Anybody please explain the above accepted output how it comes and the meaning of the above problem statements.

And finally here is my code which getting WA:

Code: Select all

#include <stdio.h>
#include <string.h>
int main()
{
    int t, i, len, j, c, Y, cas=1;
    char input[100], replac[50], output[110][100], check[100], ch, blank[5], base[100];
    strcpy(replac, "xkqsupmjfgdbehcayrvoinztlw");
    strcpy(check, "xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj");
    strcpy(base, "the quick brown fox jumps over the lazy dog");
    scanf("%d",&t);
    getchar();
    gets(blank);
    while(t--)
    {
        c=0;
        Y=0;
        while(gets(input))
        {
            len=strlen(input);
            if(len==0 && input[0]=='\0')
                break;
            if(strcmp(input, check)==0)
                Y=1;
            for(i=0;i<len;i++)
            {
                ch=input[i];
                if(ch>='a' && ch<='z')
                    output[c][i]=replac[ch-'a'];
                else
                    output[c][i]=ch;
            }
            output[c][i]='\0';
            if(strcmp(input, base)==0)
            {
                strcpy(output[c], base);
                Y=1;
            }
            c++;
        }
        if(cas>1)
            printf("\n");
        if(Y==0)
            printf("No solution.\n");
        else
            for(i=0;i<c;i++)
                puts(output[i]);
        cas++;
    }
    return 0;
}
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Post Reply

Return to “Volume 8 (800-899)”