数学建模社区-数学中国

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

作者: Winter_moon    时间: 2011-3-19 15:26
标题: 谁来帮忙看一下这个题错在哪里?
Cryptoquote
( q5 h& l$ [5 o$ D2 h! v& A9 ?/ c( C! o- ?/ E
& i% l* ^9 Z9 p* f) F% R7 M  f* \: B1 h
Time Limit: 1000 ms Memory Limit: 65536 kB
! Q4 x8 ~4 F$ i7 j2 s; x: s/ H" ASolved: 79 Tried: 281 * `) {; C5 f4 U

+ c8 B0 H5 D8 ADescription 2 M3 b. ~; [8 {6 t
A cryptoquote is a ** encoded message where one letter is simply replaced by another throughout the message. For example:: K2 y: S: \0 j7 E0 f

9 y' A: H( f; o% Q8 {Encoded: HPC PJVYMIY 3 C9 U. ?& v; ]# w$ C
Decoded: ACM CONTEST( I) H1 J9 r1 W: O$ D$ W9 k# p  t, C

9 f1 u- g6 H  ]' VIn 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.
+ I" {' y# i) q- y- O# j8 X& j3 `3 o" b6 b$ ?5 ]) h6 f

- Y1 D3 X( e0 q8 L( u" FInput 1 ~9 b( Z9 N# d: `( m0 f4 `4 x1 @
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.' V" M; M6 ?9 A  E0 T

" i% D+ i7 Y5 k) R
! s% B  e5 D7 z
; f1 M# i& f' v7 C0 w& @4 c! @Output ' p- J7 q; h! ?4 ]' v
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.
: Z: K/ G0 q8 P' ]3 E
" i- C% u  W* g& i, \/ Z
* _; \$ z' r: mSample Input
$ ^$ \$ [4 }/ h6 c2
! D. E8 l  X7 y/ AHPC PJVYMIY 8 q2 A, j0 V% K1 U* J! T
BLMRGJIASOPZEFDCKWYHUNXQTV ' l6 ]  T9 K* _# }: z% P
FDY GAI BG UKMY 8 @' G3 N1 `0 o' Y& N; ?
KIMHOTSQYRLCUZPAGWJNBVDXEF5 c: J5 x2 G3 J; u4 i  N
  [+ H! W! ~$ j/ K' d' _$ v8 N6 Q
: A# K2 G! ?% T+ J) O" t  z% E- b
; T- ?, \* X* x  ^# G8 s% n4 H& Q
Sample Output + ]; F; B1 t( }9 }( F" F- P
1 ACM CONTEST
. H& S4 v& C% _( o- [2 THE SKY IS BLUE
, Q6 \3 J) f. r. G
: t+ L( w' w  L- A* w/ h  }3 H2 b& x, z% W
: f) R+ H7 b! F  o: U, y
我的代码是:
1 B& N* J) i$ q3 b8 e. j( z#include<stdio.h>
* m$ X0 l- `& J+ F# f#include<string.h>5 d  Q# _4 G9 a, t
int main()
( k' l/ W* f3 H, E{/ i1 B2 n7 i+ W" \# L, R
     int N,i,j,k;) R5 q- h# T' j( j
     char c;
' T) I  V2 S' G2 t: S  n     char code[1000];
1 B+ k; ]: T+ ?* ]- k     char map[27];
4 K  G  X7 f/ y2 \     char trans[1000];) c$ n" \- o" b- |$ X) H' Q% H& I
     char wrong[3];
: G3 s$ d, i! J& v     scanf("%d",&N);/ v5 `8 b( H  G" w
     gets(wrong);3 b6 h3 u3 j6 d" h9 e% b
     int h=1;
3 `# m) l# q4 V1 }     while(N--)5 _6 V3 P4 l- I, i* x6 r; F! ^
     {+ X2 T1 E- [+ J5 |( H. O; S9 l
         gets(code);
9 B' c- A7 e" r6 S# j/ s( i* _$ m         gets(map);
* c' d6 d+ {5 P" H/ I         for(i=0;((c=code[i])!='\0');i++)2 p0 @# }8 ~# L' @
         {
+ v& i1 [3 \, i+ @) Q             if(c==' ')trans[i]=' ';$ T& \$ p- \+ k3 U9 e1 I: R
             else {j=code[i]-'A';7 ?. f/ a# @" C$ j
             trans[i]=map[j];}       }; c* T4 w6 I; L6 h/ e9 {
         printf("%d ",h);
7 w* L& Z( N) A' T5 Q; j% |         for(i=0;((k=trans[i]<=90)&&(k=trans[i]>=65)||(k=trans[i]==' '));i++)
& n/ ?  }7 k% p3 d- `         printf("%c",trans[i]);. K1 I! R! W& ^1 r0 K
         h++;
% i* I+ A0 J* u' Z8 V         printf("\n");6 G" T  ?4 _& e8 t  E7 M+ f3 e
     }$ ]9 L* n0 O/ `* X% I( n5 l
     return 0;9 p1 d& {% J% c( K* g
}
( y3 Q1 d/ L' b: q: E" [, N; h9 v4 _1 `6 ~7 o& \

" g1 H- w6 H  _: u% c样例过了,但是提交答案的时候还是wrong answer。是哪里有陷阱?
2 U0 U, a- U2 g7 c7 ^4 i% W* a2 z
作者: zjqylcy    时间: 2011-3-19 22:26
把答案也附上来吗。。。9 n/ c. H& w7 p# u" |
是不是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