数学建模社区-数学中国

标题: 谁来帮忙看一下这个题错在哪里? [打印本页]

作者: Winter_moon    时间: 2011-3-19 15:26
标题: 谁来帮忙看一下这个题错在哪里?
Cryptoquote
4 {' S7 V/ e7 [3 O  o
$ r, E# c% z, b5 n# [0 n8 L, R" O" ~% Y* H6 f( g
Time Limit: 1000 ms Memory Limit: 65536 kB) l. L4 w; A, x' h# E) e
Solved: 79 Tried: 281
$ i0 {  n4 r/ i; `( n2 N- n0 [6 \/ Q9 d7 ^$ \) H( v- r: U8 p
Description
$ ]. @# r% {+ Y: T- NA cryptoquote is a ** encoded message where one letter is simply replaced by another throughout the message. For example:! @# ?" k5 e5 k& \

! J6 }& F: W4 {2 \  NEncoded: HPC PJVYMIY & w, C8 {2 D+ @* ^
Decoded: ACM CONTEST
, e2 j9 |4 l+ j" m$ o) Q3 Q! @. q( J  Z6 V, H) x6 {0 N
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.
6 j) m5 K) j. b8 [# Q$ f0 n
0 a3 r+ X3 W1 t1 t
, `2 }- S. H0 l3 kInput " A7 X& U8 i- f, r5 c0 Q! I# X4 f8 Z
The 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.
: W& P1 L5 X- z2 ~3 _3 U& @8 Q5 v5 I
- x" f' R& g  I1 L

$ @2 A7 K9 I, ]Output
( v' Q" U0 V3 JFor 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 b! g. S. n( s- q" @
$ {& B5 H# o' T$ v# p0 `3 g8 h
! ?  j* F& M; ~0 ~1 m1 s
Sample Input " b7 Z, q# u# X# O: L% m
2
4 Q: ~! H* H" _: C; ]% zHPC PJVYMIY , f/ M) A6 C' `. E  g6 R7 G
BLMRGJIASOPZEFDCKWYHUNXQTV 0 s4 _+ M1 z' u9 z& Y+ _
FDY GAI BG UKMY ; M/ ?% g4 e2 H' g* k* ^
KIMHOTSQYRLCUZPAGWJNBVDXEF
+ z- ]8 k# U, {" [0 I
9 X+ S$ w6 l& d  u8 k1 u
$ X7 e: @# p! G& V$ m
7 E  U+ R' ^4 P1 `4 Q  GSample Output 7 F& M. k& u+ e1 q3 a- f
1 ACM CONTEST * s! j3 \* X9 Y) Z9 T0 n
2 THE SKY IS BLUE" p* N) W" J6 [1 z% R& _  h; m
0 ^) c0 H( E! t2 d5 Z- c2 D

/ A. \) h0 l0 \$ O+ z( ~
0 E- `. J$ v) K* n( Y& r! ~我的代码是:
( x2 X( C8 K% ~( `" ^9 k#include<stdio.h>
' H1 z- m0 G; Z- {( J/ B( W#include<string.h>6 D2 T! b& u6 @% c
int main()9 o2 }5 H8 E# k6 a& Z9 R
{
5 H7 g0 U% N9 w' @7 K; ]$ _     int N,i,j,k;
- i. y, A0 G# I( o5 ]# Y  A3 W' a* I     char c;! q" y! Y+ z7 ~0 U# F7 h9 U
     char code[1000];8 z& s: @% D6 _+ P! S8 a
     char map[27];
" m% E3 C5 {( T9 y0 @6 o$ o     char trans[1000];
* K: V- q) q/ T# o& y( K2 u) p0 A     char wrong[3];; ~4 h1 t! b6 C
     scanf("%d",&N);' z8 |' [: I# w6 u, J3 `
     gets(wrong);
- D$ x! \1 S: s( d8 e     int h=1;
# D; {9 o6 D( S. x; r     while(N--)
( W; G# x+ F# I$ |     {, L) h' d. z9 z5 k1 l' P
         gets(code);
; D! j; g- Q/ R- x         gets(map);
8 V& C; D, r1 p4 l         for(i=0;((c=code[i])!='\0');i++)" M) N; ?# ?) r( C3 ]8 J
         {
+ X1 M8 e* Q$ R- D( Y. w) r             if(c==' ')trans[i]=' ';
  m) B  j9 `+ f9 s1 a% Z% S) C             else {j=code[i]-'A';3 c# k2 M6 v. N- F! h2 S: Z% V* {$ L8 z
             trans[i]=map[j];}       }. g- `7 `& J1 T) N9 P# R2 G5 O
         printf("%d ",h);; x* d; L, s7 n# w$ @+ T! g: X
         for(i=0;((k=trans[i]<=90)&&(k=trans[i]>=65)||(k=trans[i]==' '));i++)( d3 i1 O5 B; Y0 p% n& \
         printf("%c",trans[i]);7 }6 m3 C0 Y* V3 l
         h++;
# `8 @8 Z- u+ u- |         printf("\n");3 d# K  Y: Z, Y& X
     }1 k6 a' `9 N+ H( B" _" ]0 q. F
     return 0;! ?7 S9 j5 h" }0 g: Z
}
* [- @- c" z2 @7 ]5 k( a* e3 Q$ X: H6 U8 o' ^9 [5 I

* C6 G& E- b& a$ W, _, N  s2 q样例过了,但是提交答案的时候还是wrong answer。是哪里有陷阱?
* j2 [8 ^) x& q' i% {8 M" I
作者: zjqylcy    时间: 2011-3-19 22:26
把答案也附上来吗。。。; \. ~  ~$ ]7 a& X" m% `
是不是k是int型?
作者: 葉_浅浅    时间: 2011-3-20 16:45
.....................
作者: linmatsas    时间: 2011-3-20 23:27
C………………………………
作者: _我还活着    时间: 2011-4-29 18:56
没有看懂.....
作者: huangliao6252    时间: 2011-5-6 00:49
int h=1;这个定义应该在 scanf("%d",&N);前面。




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5