Cryptoquote ! @% Q3 t6 o( w+ I z T
+ d6 y, a* b3 G* ?
3 O' ^$ N" O7 s
Time Limit: 1000 ms Memory Limit: 65536 kB+ Z7 y4 O7 w" t% n
Solved: 79 Tried: 281 ; b' [- Z/ Q) d) D5 r# Q2 T( L+ P# d/ Y9 O0 U. j; Y4 i- s
Description 7 v2 _, W: y/ N2 I( v# ~
A cryptoquote is a ** encoded message where one letter is simply replaced by another throughout the message. For example: [3 r$ ~' v. }9 T2 v0 n3 J* e
7 i- m7 E5 p, Z& O8 {
Encoded: HPC PJVYMIY % J1 P4 m- h# ~2 MDecoded: ACM CONTEST6 h; o' K5 s: ^$ j
4 ~; \5 [, l7 F' e) L T
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. % M( W( ?% X z2 J' c
- ]1 x5 G0 A1 @& I& ^( P# O* ^- O7 P3 F/ v- B! {8 S
Input # P9 y6 `8 P! `% ^9 `) ^4 \" @# hThe 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.* H8 J' Y( d1 M5 ]
T2 T6 C1 f$ b- s4 T " A: n% { _3 q$ O7 q " x( J; X1 S* K) D$ Y3 B* P8 cOutput ' o( b8 ]$ T, c2 w( |; S' y
For 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. 0 r( Q' g E! N1 i( o) u 2 S* ^) k" F7 Z( x( k! D9 q % y2 ]% f( ~: g3 h6 `5 QSample Input 9 x) b! K& ~# p% ]2 ! _4 S) ]4 H! u7 Z) I
HPC PJVYMIY % G) s; I% ~4 \BLMRGJIASOPZEFDCKWYHUNXQTV % q% a0 w% `( C) ?5 _
FDY GAI BG UKMY ' x J! j! s2 S. {- ^# a( r7 W) E
KIMHOTSQYRLCUZPAGWJNBVDXEF $ o' b( ^" M9 k 4 G& {" R+ [* O; V! m 7 K+ W0 e& b( ~0 I+ K S , K5 m' L; v5 } V% {5 X# MSample Output ( x/ ~' y/ L: s7 [; O S
1 ACM CONTEST , l% x. x9 V# t; Y3 u2 W/ c
2 THE SKY IS BLUE# ?8 V9 `1 a1 X& M( D8 z
4 A; \7 s- ]. T9 Q) [$ B" D3 M& R
0 t) } h; ]+ g) o
/ f* L. Q5 j6 n C
我的代码是:$ F" r; j9 H; U, a1 F* g$ ?$ w+ i
#include<stdio.h>7 C1 |" O9 K8 D# N: J4 k: b
#include<string.h> 6 j5 p M, ]9 V- ^int main()3 f& k2 J4 p' J! Y/ `; y! s. }
{ . {7 |- ?1 K/ O q; v4 j2 Z' o9 m int N,i,j,k;$ G" L% n" e9 H& O
char c;$ Y) n+ x. w+ y& [+ O
char code[1000];- ^) W9 H. t4 c7 w9 h# ~
char map[27];0 D( O) E* D$ H0 b' S7 K; K$ G
char trans[1000]; : o* B, t) F1 Z J0 } char wrong[3];% O+ ^8 J: q+ O6 J8 R# ]: v, _
scanf("%d",&N); : H5 D" R1 u) c. t; c( R% R gets(wrong);( C3 h( Q- I: B4 e
int h=1; * X8 Y3 c; G) e, h while(N--)) ]3 ~0 S K- F8 z, V6 v
{ & G; ~6 m r$ _: H2 G4 @9 b; Y: G gets(code);7 S$ U- N" q& Z" V
gets(map); 4 r+ _; F1 U! W, D/ T for(i=0;((c=code[i])!='\0');i++); e9 n9 \$ `& ]; E5 _
{3 h8 h, }3 j/ G
if(c==' ')trans[i]=' '; , R4 }7 o0 k. I( U2 Q7 u else {j=code[i]-'A'; ! N) t- L; c+ g trans[i]=map[j];} } : y' x6 a8 f0 ~( ?( U+ d' Q; s% x printf("%d ",h); % N: U0 F7 u2 j; F for(i=0;((k=trans[i]<=90)&&(k=trans[i]>=65)||(k=trans[i]==' '));i++) ! V* g, C6 i! d( }+ N printf("%c",trans[i]); p7 ~6 p' N A; s6 `7 S h++;6 s2 O( l3 a9 M, X7 ?$ Q6 R6 M
printf("\n"); 6 a" `+ W8 q# ?7 v }3 O; V1 l, ?+ p3 A* \9 R/ m1 q# i
return 0;% x! r8 w2 `( c
} ^2 j, t7 o, H& u7 C; ]8 I. V
7 A) C$ V6 @9 H# E @& O+ d
- d" Z% Z- U" P: K
样例过了,但是提交答案的时候还是wrong answer。是哪里有陷阱?; K# E8 b8 i0 u S# h