数学建模社区-数学中国

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

作者: Winter_moon    时间: 2011-3-19 15:26
标题: 谁来帮忙看一下这个题错在哪里?
Cryptoquote
& k- Q$ n4 _( u' ~$ A' n4 f
+ i# E3 a, X6 R" E# U
6 I5 u& s: c( Y; n1 Q( jTime Limit: 1000 ms Memory Limit: 65536 kB
; S% K" u7 R. }( N0 vSolved: 79 Tried: 281 9 Y$ A* D9 ^( Z( a" h
( J# Y: l& i& y* u1 f3 U6 x
Description 4 w! L1 K* b7 l$ V% K/ f
A cryptoquote is a ** encoded message where one letter is simply replaced by another throughout the message. For example:
8 U6 o' P# ?: I& @- @- s5 Q6 n
' x( M! Z7 t6 M! NEncoded: HPC PJVYMIY 8 r) }) ?) _; w
Decoded: ACM CONTEST
: o- ?' [, {4 r0 M& A  u% a& ^8 c6 o- G
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. # [( d, W) P+ H5 G
) @6 j( p( u2 h' O/ a, o- ~/ n: y

4 o. l/ e4 z! B$ A) ~" J! P. cInput
; |1 E  f9 D5 g6 BThe 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.
6 Y: r8 e: Y1 O9 ~7 m  H# P. `
. l) y! t7 n1 g- T( e" T( T( x& v( Z: G. W* |! c
; D2 J1 L% ?2 Y7 C& g( J3 [1 V
Output ' v3 I' e2 o7 y- h
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.
* V* i0 O8 H+ B; \8 k2 W
. W/ L7 {! J5 ^
. z( Q  u. i9 N4 a2 Y) |Sample Input
* t" A9 v$ K7 x4 T# b9 v: `2
3 k! _8 J. ~! |) b1 THPC PJVYMIY
( s- s0 S; y4 C6 k/ ^- t7 m% H2 ?+ DBLMRGJIASOPZEFDCKWYHUNXQTV
' n! E0 v# j& T1 @FDY GAI BG UKMY 6 a7 F, F) w+ p7 s' i6 r
KIMHOTSQYRLCUZPAGWJNBVDXEF
: s+ H* B2 @, U6 F; k3 J, E+ `8 ~/ k$ Y! z4 {9 r4 r" F
6 B* w% ?4 P' ]0 @; o+ c
4 m" D8 _! J& l' Y) ]
Sample Output
  E/ J+ X& |' I2 M3 X; W$ g) b1 ACM CONTEST
5 C2 Q1 Y. t2 p  S# D5 J2 THE SKY IS BLUE
% a' x, T6 g: E. J4 c6 j" Q1 a+ _; i
3 r0 B, |- P. M! m+ K2 w1 c& \. O) B

0 c' z$ E4 f* K! a我的代码是:  @( J* O0 B5 k  A- d3 r
#include<stdio.h>: P. p) |7 w+ B: s
#include<string.h>7 B6 L, p. A, A: y
int main()
$ c/ _) J9 N. s6 }/ J/ o2 {{
7 ^+ c8 e/ v+ \0 E: P9 y/ `& h     int N,i,j,k;1 h* j$ A0 q9 B' C
     char c;3 i( q) e% v$ q  T8 K
     char code[1000];- k4 j+ D. D/ o3 e  k6 X' [
     char map[27];0 p5 e1 q0 m$ ~* W& r8 ~$ D% `* e! h
     char trans[1000];
0 n- g; ?2 ~2 ?2 b" B! Y  S. s! K" N     char wrong[3];
% X  C5 h$ d( [% U# ~     scanf("%d",&N);2 x" v5 l' ?$ K4 X: l' Y# s
     gets(wrong);. d) j; l) W+ Q9 z1 m6 U
     int h=1;: z5 x1 h5 J0 P8 D
     while(N--)
/ @( b) e1 P3 b! {7 P     {
$ d* Y# o, n; p3 B         gets(code);: O* J2 R0 F7 }0 l
         gets(map);
7 x5 {2 r+ |! s) t/ D         for(i=0;((c=code[i])!='\0');i++)
% B* I' a2 B* |& Z, i9 h         {
9 r& D3 {/ n$ E" c& s6 s1 o8 `             if(c==' ')trans[i]=' ';
, n  t8 ]# A: j# H9 j5 [             else {j=code[i]-'A';+ j0 B  Y* V$ `
             trans[i]=map[j];}       }( ^0 ^  k. P9 p; \$ ?9 E
         printf("%d ",h);
& R% s1 ^8 U6 o7 N. c' Z         for(i=0;((k=trans[i]<=90)&&(k=trans[i]>=65)||(k=trans[i]==' '));i++)8 D1 w6 l, Y" Z5 g, l0 w
         printf("%c",trans[i]);8 j/ \7 F/ I# \# \0 c5 D
         h++;
8 ~) k2 o/ [* R8 @) }         printf("\n");0 Z5 y1 s- c6 E) E
     }
! \& h  Z+ x9 k7 U6 t: s! F# L     return 0;
; l+ f  l1 c, g% ~7 R}
0 S4 H- w: r) w' R* `
' |! h5 k- B6 y$ x
, j. i# b8 i' l9 _. }1 Y样例过了,但是提交答案的时候还是wrong answer。是哪里有陷阱?( \& X  O  {6 d$ g

作者: zjqylcy    时间: 2011-3-19 22:26
把答案也附上来吗。。。
- g: z7 G& q; X% o是不是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