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

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 850 - Crypt Kicker II

Post by lighted »

..one of the lines of input is the encrypted form of the plaintext "the quick brown fox jumps over the lazy dog"
According to problem description one line of input block is encrypted form of "the quick brown fox jumps over the lazy dog". It doesn't always equals to "xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj" as in sample. It may be different.

Code: Select all

xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
the quick brown fox jumps over the lazy dog
For sample decrypting (replacing) is as follows
x -> t
n -> h
m-> e
c -> q
e -> u
..
and so on

Input

Code: Select all

1

now is the time for all good men to come to the aid of the party
oju yifqd krczh pct gieav cnur oju bxwl scm
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
the quick brown fox jumps over the lazy dog
programming contests are fun arent they
In this input there is three encrypted forms.

First

Code: Select all

oju yifqd krczh pct gieav cnur oju bxwl scm
the quick brown fox jumps over the lazy dog
Second

Code: Select all

xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
the quick brown fox jumps over the lazy dog
Third

Code: Select all

the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
You should use first found encrypted form.
If there is more than one possible decryption (several lines can be decoded to the key sentence), use the first line found for decoding.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
anacharsis
Learning poster
Posts: 69
Joined: Mon Feb 09, 2015 1:56 am

Re: 850 - Crypt Kicker II

Post by anacharsis »

It appears that there is no blank line after the last test case.
So, process last case after EOF
Hallway
New poster
Posts: 2
Joined: Thu Mar 30, 2017 10:30 am

Re: 850 - Crypt Kicker II

Post by Hallway »

I hava tried serival test cases , but still got WA.

Code: Select all

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

char map[256];
const int MAXN = 100 + 5, MAXL = 100;
char encryptedText[MAXN][MAXL], text[MAXL] = "the quick brown fox jumps over the lazy dog";
int n;


bool compatible(char *str1) {
	for (int i = 0; str1[i] != '\0'; i++) {
		if (str1[i] == ' '&&text[i]==' ') continue;
		if (str1[i] == ' '&&text[i] != ' ') return 0;
		if (str1[i] != ' '&&text[i] == ' ') return 0;
		else if (map[str1[i]] == '\0') map[str1[i]] = text[i];
		else if (map[str1[i]] != text[i]) return 0;
	}
	return 1;
}

void solve() {
	n = 0;
	char str[MAXL];
	while (gets(encryptedText[n])) {
		if (encryptedText[n][0] == '\0') break;
		n++;
	}
	int line = -1;
	for (int i = 0; i < n; i++) {
		memset(map, '\0', sizeof(map));
		if ((strlen(encryptedText[i])==strlen(text))&&compatible(encryptedText[i])) {
			line = i;
			break;
		}
	}
	if (line == -1) {
		cout << "No solution.\n";
		return;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; encryptedText[i][j] != '\0'; j++) {
			cout << map[encryptedText[i][j]];
		}
		cout << endl;
		//fout << endl;
	}
}

int main() {
	int cases, cnt = 0;
	scanf("%d ", &cases);
	while (cnt < cases) {
		if (cnt) {
			cout << endl;
		}
		solve();
		cnt++;
	}
	system("pause");
}
Post Reply

Return to “Volume 8 (800-899)”