数学建模社区-数学中国

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

作者: Winter_moon    时间: 2011-3-19 15:26
标题: 谁来帮忙看一下这个题错在哪里?
Cryptoquote 1 ?# g# R" R) v& v6 x9 A
: Z% ^: m; h* w5 L3 H1 q  o! o

$ _; H3 \" j; y5 ^# E: d/ \( VTime Limit: 1000 ms Memory Limit: 65536 kB
: Z2 d. Y  T/ i7 Y4 e9 d. A% WSolved: 79 Tried: 281 8 K0 s* ]  t; n6 P

4 S) r5 a7 G- E1 S7 b+ G1 q# JDescription , W% v! _0 s1 n) b) Q* P
A cryptoquote is a ** encoded message where one letter is simply replaced by another throughout the message. For example:
/ L- ~/ f9 q/ x5 W2 M9 e" [# K8 E' ~
6 e3 |( Q7 @) o, d: ?Encoded: HPC PJVYMIY
4 I7 P2 {. U+ |3 @: E4 VDecoded: ACM CONTEST
/ }' |9 Q& X) [) n4 X* b
! k. P5 q. V; @5 UIn 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.
/ a$ i+ U. T: t1 c% C5 ~
9 S' v. d) Y: b! F6 m. a0 k6 \" G
. P; @& M9 Q, J9 |  eInput ; q2 P2 n* @  W
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.
0 [2 z6 k9 t5 b0 m# v5 I" N# F) D9 H, |5 q/ _9 S( F

9 f! D0 a, P' o2 q/ _" b3 t$ i/ c8 j7 m  p+ P
Output
- [/ y- H* x2 [. {# T: hFor 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.
# ]6 E; E' e2 ^, E% y+ D
6 q! q  H9 Z" V
( m3 H2 z: U( o: P: HSample Input
. L+ t: [1 |! O" ?! \. c2
! a8 \2 |; }' K' lHPC PJVYMIY
4 x/ Z* s  ?  }' b) M- I% nBLMRGJIASOPZEFDCKWYHUNXQTV : v8 @5 E* A1 e$ p( M  _, K) ?
FDY GAI BG UKMY
& ^" G: @' W9 hKIMHOTSQYRLCUZPAGWJNBVDXEF
  Z1 M, X; z! D8 b9 o1 e% N* g- d/ R6 N  X; d; n. R$ N5 S( V3 h

0 R$ y" I. }- Z& v5 H" T! v% S+ }9 a1 H; ?
Sample Output 8 l: n; _3 ~9 v5 _, d1 L/ E/ N
1 ACM CONTEST 7 E! v: {0 Q+ l7 V1 N3 l. n
2 THE SKY IS BLUE4 u: e  Z) a9 [8 o( }+ C

& m- c; y% Q1 V( X/ v0 Q4 q
  o! B  H: ~, v* ?# K8 N0 K% f) A6 Q  o
我的代码是:' m% R3 i2 u9 d$ ~1 s% \4 d
#include<stdio.h>
/ O! i# U: K& ^#include<string.h>
" |% {/ y0 U( B) Y/ Y0 U$ U+ C2 Mint main()
: ~& D$ H/ r5 [# ?1 z# w# w& m% N{
  v( m, k/ L% P8 B     int N,i,j,k;
7 k6 i% F5 u, @# E# D     char c;
/ {3 ~# N0 [& U     char code[1000];
7 I6 l5 b  I6 B+ x8 W) e     char map[27];# A7 M, E  L! T3 f- y( u
     char trans[1000];$ Q7 {$ Y1 T" ^
     char wrong[3];
) a( E% w; F  K9 b. `     scanf("%d",&N);
$ y3 B  `1 c+ f  o( c9 F     gets(wrong);
3 M7 [! G- W. c$ s! }8 i- |     int h=1;
6 e; t; b# y' A     while(N--)
2 A/ L. }+ c# u  D& M5 j3 e     {$ u" D$ y7 o* s
         gets(code);
' B' I/ s" v: e7 X; \4 l* m4 @8 N         gets(map);# ~* a" V. Y1 @3 s
         for(i=0;((c=code[i])!='\0');i++)
/ b: Y8 ?/ x+ R7 i9 d         {3 D0 _) |& \/ j! q
             if(c==' ')trans[i]=' ';
% S- |8 \% P" b0 A+ @+ _             else {j=code[i]-'A';
! Z( N( V$ u% y7 ~* d' y             trans[i]=map[j];}       }
7 J4 J0 G% _. R         printf("%d ",h);
/ C: Z3 h$ L( G. a3 L         for(i=0;((k=trans[i]<=90)&&(k=trans[i]>=65)||(k=trans[i]==' '));i++)
( [1 S- g# U! }+ c  v: x$ m         printf("%c",trans[i]);4 U4 T* L+ W  {/ ^1 X- _/ ~" d6 E
         h++;0 j  Q! M( Q. O2 U6 t% @4 r3 c
         printf("\n");- {( b, I/ \7 j+ @  X* M' a
     }
% R1 y# q1 m0 ~* W1 W  Z     return 0;
* A% O4 j: K3 N2 R}& q# D+ ?/ L1 \# s6 |6 t' o

' P* D1 x' G# T% J, c6 z2 _! N* _- @+ Y' s4 Y% x
样例过了,但是提交答案的时候还是wrong answer。是哪里有陷阱?
8 C$ W+ E6 r+ d, w2 n
作者: zjqylcy    时间: 2011-3-19 22:26
把答案也附上来吗。。。+ S( n% o+ q; |( @; z: s; q
是不是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