Cryptoquote 1 S4 T" }( V3 t1 ~, N* i' L
\$ x7 u! p v# }
/ W9 }; V2 q, p8 h) u( mTime Limit: 1000 ms Memory Limit: 65536 kB7 @- j$ {/ y) k6 D# t. G0 O: D
Solved: 79 Tried: 281 7 r( S7 s2 U$ g6 S0 @6 x
* S, `8 h/ G) K3 |2 ]
Description " ^# @0 I8 X1 l3 x2 s5 }9 W
A cryptoquote is a ** encoded message where one letter is simply replaced by another throughout the message. For example:8 P2 r5 o k( ~* q0 E! o% E" ]. v! }
: P0 D7 r: r& ]/ j
Encoded: HPC PJVYMIY 7 J6 w2 `- `4 z$ L. Z$ r5 w
Decoded: ACM CONTEST/ w& [+ Y" Q- u% p! L+ Q; K+ c
7 c) P0 X; i# [2 }& H- a3 n, c5 Y; V
In the example above, H=A, P=C, C=M, J=O, V=N, Y=T, M=E and I=S. For this problem, you will decode messages. # v# q9 _: O4 l: q% m/ J
+ t9 M2 E; }, m/ a$ F+ E* l2 m3 C) G+ Q) F! |+ B7 ~
Input $ x2 O! y; E6 r# ~" {9 V/ W3 aThe first line of input contains a single integer N,(1<=N<=1000) which is the number of data sets that follow. Each data set consists of two lines of input. The first line is the encoded message. The second line is a 26 character string of upper case letters giving the character mapping for each letter of the alphabet: the first character gives the mapping for A, the second for B and so on. Only upper case letters will be used. Spaces may appear in the encoded message, and should be preserved in the output string. 7 F/ k/ C& G5 _; o o& [ 2 P4 J- X" l0 B, \& Q& `: e7 H6 ] % `& V2 Q: ?, ?) r# Z" B" c 9 l2 @1 X% z6 S- y QOutput 2 F# A& E- Z3 }9 L1 ~4 f. qFor each data set, you should generate one line of output with the following values: The data set number as a decimal integer (start counting at one), a space and the decoded message. 8 \7 W9 o+ O! D: H. g
}2 C) ?; T) d- a/ P& j+ [0 s! m+ K) L& w7 ?7 T
Sample Input : U# U7 u, k9 T$ h2 $ y7 k7 ], U+ `- i! ^
HPC PJVYMIY - S8 M C1 p3 VBLMRGJIASOPZEFDCKWYHUNXQTV 7 s& {2 h9 e0 x
FDY GAI BG UKMY ) G9 D7 j$ K$ g- k0 k2 G9 ? vKIMHOTSQYRLCUZPAGWJNBVDXEF/ d* p/ ]2 }, i J2 f7 l) v
( P* O* E* Y8 z# m% R
' H6 n5 [) k, W, r0 A
% l- u# I8 r: q8 J# M
Sample Output 5 a/ M, m2 p6 M# d. J
1 ACM CONTEST 6 |! y4 T' F5 ]+ v, H2 THE SKY IS BLUE 2 y8 g' }- A' m c6 n, Z$ H: n' X1 o! k" R6 |
2 g& O' c" }% `7 Y" }% u
8 ]4 I4 c N8 B1 I3 ~4 V# T
我的代码是:1 W5 J; Q% w8 Q$ [8 R' [
#include<stdio.h> M8 c* I/ B& K8 @/ i# z
#include<string.h>. C9 D7 c. [5 C+ J1 f/ I/ O& s1 l
int main() - o9 u* f9 l. l+ Y7 K+ n! a{ p2 [* [4 \2 H* |: `# P
int N,i,j,k;3 A0 r6 ^% c( s7 P
char c; ; O, h5 a. U6 q: p9 G5 ^ char code[1000]; , Y" n R& t6 } char map[27]; 4 E) N9 K+ l) d, \1 k d$ h! x char trans[1000]; ' {2 b; S7 x4 W char wrong[3];" H2 z; v; j& G8 J4 e
scanf("%d",&N);" w i" k+ [& m9 H
gets(wrong);6 O: {2 v( I1 b4 ^' X" f+ c
int h=1;6 Q9 v: z: O" Q; ^( x* {$ i
while(N--) " h7 x$ F; m3 N* @9 G j {3 B C1 e [; p( H
gets(code); 9 ]# U% ^5 K- |. j gets(map); 1 ~3 ^& C i) Q; X/ G% \" s N for(i=0;((c=code[i])!='\0');i++) & X& W/ i3 Q6 J. ` {8 ]/ h! r ]8 b8 a- y( _
if(c==' ')trans[i]=' '; % I" L) a! o, c/ Z else {j=code[i]-'A';3 B6 f! q, c4 b5 j# K5 f9 l) f
trans[i]=map[j];} }* `! k+ {3 v* _5 ]9 I
printf("%d ",h);* g+ V* U2 Y/ o! L4 @
for(i=0;((k=trans[i]<=90)&&(k=trans[i]>=65)||(k=trans[i]==' '));i++) . _0 ~0 P3 J: S printf("%c",trans[i]); / M2 S6 a3 Y+ U/ D7 S h++;+ c+ l0 ~; |/ d$ _
printf("\n");: W7 R* N$ t+ D! A. S
} ! w5 [9 D9 ]1 D& u8 { return 0; ; p, \6 n4 [) s6 }0 k% q# E, l, i} , j U! f* c6 y0 m) k/ P; F' r ; m7 j3 l8 w9 _$ Y# ^: j 1 U. Q, o' {4 |, r6 M& F, f. U2 L样例过了,但是提交答案的时候还是wrong answer。是哪里有陷阱? - s T: w7 q, V% B7 f; ^5 ^; O