Cryptcowgraphy,奶牛加密
Cryptcowgraphy
Brian Dean
The cows of Farmer Brown and Farmer John are planning a coordinated escape from their respective farms and have devised a method of encryption to protect their written communications.
Specifically, if one cow has a message, say, "International Olympiad in Informatics", it is altered by inserting the letters C, O, and W, in random location in the message, such that C appears before O, which appears before W. Then the cows take the part of the message between C and O, and the part between O and W, and swap them. Here are two examples:
International Olympiad in Informatics
->
CnOIWternational Olympiad in Informatics
International Olympiad in Informatics
->
International Cin InformaticsOOlympiad W
To make matters more difficult, the cows can apply their encryption scheme several times, by again encrypting the string that results from the previous encryption. One night, Farmer John's cows receive such a multiply-encrypted message. Write a program to compute whether or not the non-encrypted original message could have been the string:
Begin the Escape execution at the Break of Dawn
PROGRAM NAME: cryptcow
INPUT FORMAT
A single line (with both upper and lower case) with no more than 75 characters that represents the encrypted message.
SAMPLE INPUT (file cryptcow.in)
Begin the EscCution at the BreOape execWak of Dawn
OUTPUT FORMAT
Two integers on a single line. The first integer is 1 if the message decodes as an escape message; 0 otherwise. The second integer specifies the number of encryptions that were applied (or 0 if the first integer was 0).
SAMPLE OUTPUT (file cryptcow.out)
1 1
我卡在第4个数据了。
数据
Begin the EscCCCCCCution at the BreOOOOOOape execWWWWWWak of Dawn
标准答案是有6个
我的程序做出来许许多多的答案,经过手动检测,好像没有重复的。。。
大家帮忙看看(其实我的程序做出来1000个左右答案)
1
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCOOOCCution at the BreWWWak of Dawn
Begin the Escape execCCution at the BreOOWWak of Dawn
Begin the Escape execCOution at the BreWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
2
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCOOOCCution at the BreWWWak of Dawn
Begin the Escape execCCution at the BreOOWWak of Dawn
Begin the Escape execCOWution at the Break of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
3
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCOOOCCution at the BreWWWak of Dawn
Begin the Escape execCCution at the BreOOWWak of Dawn
Begin the Escape execCution at the BreOWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
4
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCOOOCCution at the BreWWWak of Dawn
Begin the Escape execCCution at the BreWOOWak of Dawn
Begin the Escape execCOution at the BreWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
5
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCOOCution at the BreWWak of Dawn
Begin the Escape execCution at the BreOWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
6
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCOCution at the BreOWWak of Dawn
Begin the Escape execCution at the BreOWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
7
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCOCution at the BreOWWak of Dawn
Begin the Escape execCOution at the BreWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
8
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCOCution at the BreOWWak of Dawn
Begin the Escape execCOWution at the Break of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
9
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCOCution at the BreWOWak of Dawn
Begin the Escape execCution at the BreOWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
10
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCOCution at the BreWOWak of Dawn
Begin the Escape execCOution at the BreWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
11
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCution at the BreCOOWWak of Dawn
Begin the Escape execCution at the BreOWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
12
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCution at the BreCOOWWak of Dawn
Begin the Escape execution at the BreCOWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
13
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCCution at the BreOOWWak of Dawn
Begin the Escape execCOution at the BreWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
14
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCCution at the BreOOWWak of Dawn
Begin the Escape execCOWution at the Break of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
15
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCCution at the BreOOWWak of Dawn
Begin the Escape execCution at the BreOWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
16
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOCution at the BreWWWak of Dawn
Begin the Escape execCCution at the BreWOOWak of Dawn
Begin the Escape execCOution at the BreWak of Dawn
Begin the Escape execution at the Break of Dawn
;;;;;;
17
Begin the EscCOOOOOape execCCCCution at the BreWWWWWak of Dawn
Begin the Escape execCCCCution at the BreOOOOWWWWak of Dawn
Begin the Escape execCCOOOWCution at the BreWWak of Dawn
Begin the Escape execCOOCution at the BreWWak of Dawn
Begin the Escape execCution at the BreOWak of Dawn
Begin the Escape execution at the Break of Dawn
我的程序。。
{
ID:64725131
LANG:PASCAL
PROG:cryptcow
}
const
final = 'Begin the Escape execution at the Break of Dawn';
prim =973;
const
cow = ['C','O','W'];
var
ss: string;
hash: array [1..prim*2] of string;
all: array [1..prim*2] of ansistring;
arr: array [1..75] of string;
b: array [1..prim*2] of boolean;
ans,imp,exi: longint;
procedure fail;
begin
if ss=final then
writeln('1 0')
else
writeln('0 0');
close(input);close(output);
halt;
end;
function elfhash(x: ansistring): longint;
var
i,h,g: longint;
begin
h:=0;
for i:=1 to length(x) do
begin
h:=(h shl 4)+ord(x);
g:=h and $f0000000;
if g<>0 then
h:=h xor (g shr 24);
h:=h and (not g);
end;
elfhash:=h mod prim;
end;
function check(ss: string): boolean;
var
exp,t,i: longint;
s1,s2: string;
begin
s1:=copy(ss,1,pos('C',ss)-1);
s2:=copy(final,1,pos('C',ss)-1);
if s1<>s2 then
exit(false);
for i:=1 to length(ss) do
if ss in cow then
begin
if ss<>'C' then
exit(false);
break;
end;
for i:=length(ss) downto 1 do
if ss in cow then
begin
if ss<>'W' then
exit(false);
break;
end;
t:=elfhash(ss);
while hash[t]<>'' do
begin
if hash[t]=ss then
exit(false);
inc(t);
end;
check:=true;
end;
procedure add(ss: string);
var
t: longint;
begin
t:=elfhash(ss);
while hash[t]<>'' do
begin
if hash[t]=ss then
exit;
inc(t);
end;
hash[t]:=ss;
end;
procedure solve(ss: string;num: longint);
var
hs: array [1..prim*2] of ansistring;
i,j,k,data,c,bans: longint;
s1,s2,bak: string;
function ck(ss: string): boolean;
var
exp,t,i: longint;
s1,s2: string;
begin
t:=elfhash(ss);
while hs[t]<>'' do
begin
if hs[t]=ss then
exit(false);
inc(t);
end;
ck:=true;
end;
procedure ad(ss: string);
var
t: longint;
begin
t:=elfhash(ss);
while hs[t]<>'' do
begin
if hs[t]=ss then
exit;
inc(t);
end;
hs[t]:=ss;
end;
begin
if length(ss)<=47 then
begin
if ans=100 then fail;
if ss=final then
inc(ans);
{ writeln(ans);
for i:=1 to num-1 do
writeln(arr);
writeln(';;;;;;');}
exit;
end;
fillchar(hs,sizeof(hs),0);
for j:=2 to length(ss)-1 do
if ss[j]='O' then
for i:=1 to j-1 do
if ss='C' then
for k:=j+1 to length(ss) do
if ss[k]='W' then
begin
bak:=ss;
s1:=copy(ss,i+1,j-i-1);
s2:=copy(ss,j+1,k-j-1);
delete(ss,i,k-i+1);
insert(s2+s1,ss,i);
if ck(ss)=false then
begin
ss:=bak;
continue;
end;
ad(ss);
if check(ss)=false then
begin
ss:=bak;
continue;
end;
bans:=ans;
arr[num]:=ss;
solve(ss,num+1);
if ans=bans then
add(ss);
ss:=bak;
end;
end;
begin
assign(input,'cryptcow.in');reset(input);
assign(output,'cryptcow.out');rewrite(output);
fillchar(hash,sizeof(hash),0);
fillchar(b,sizeof(b),0);
readln(ss);
if ss=final then fail;
if length(ss)<47 then fail;
if (length(ss)-47) mod 3 <>0 then fail;
solve(ss,1);
if ans=0 then fail
else begin
writeln(1,' ',ans);
close(input);close(output);
end;
end.
到底哪里错了?还是我题目理解错了??
BTW,C++大家都用什么IDE调试?