找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 897|回复: 0
收起左侧

[面经题目讨论] 求解一道String匹配的题目

[复制链接]

16

主题

8

精华

395

积分

高级会员

Rank: 3Rank: 3

积分
395
发表于 5-2-2015 05:56 PM | 显示全部楼层 |阅读模式

亲!马上注册或者登录会查看更多内容!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Problem Statement 9 A  C' b( h. ]# z+ I& z

$ _- c% ^( y' a( }You have two strings A and B. Each one contains some letters and exactly one asterisk. 7 @$ b7 s% d& G0 C0 ]& m& H
  |/ P7 |- ]2 R0 c
You have to replace the asterisk in each string with a letter sequence (possibly of zero length) so that the resulting two
+ ?5 e9 A' d- Y' D- t
9 ~, k  x+ |6 |: G! F5 ^7 ?strings are equal. This equal string is what you have to return. Attempt to return the shortest possible string. . g( b( C# X) m. V1 s/ }( m& i9 p

2 @# L1 b9 `" FThe letter sequences may be same or different.
  v: i& C& O- }# H* \
9 h- g, e- w& ~# L3 i% `  xIf it is not possible to make the given strings equal, return the string "not-possible".
% V1 a% p6 ?3 ?
+ Q% n. c) t8 |7 \. W* O1 ?1 P' z8 T+ G: qAdditional Constraints
* m8 u* J4 o' F9 _1 R% L- |- Q' t7 ?7 i/ L9 a' ~5 m1 t
- A and B will contain only uppercase letters and asterisks.
5 w! O7 \+ _: w9 E3 k. G! d0 w5 N5 s
- A and B will contain one asterisk each.
: T: M- W& m0 e0 I4 q( U2 ~" L6 e! K2 b' O" l* y
Examples . C  j2 {; z* \, O" F, A$ m$ q: V

7 j4 b9 N3 \  o" l6 {9 h" `7 e0)
+ D0 X& S! T7 F. V( q9 g! W
- u; o8 R( j& \. j( r"SOCIA*TWIST" # y* D- J: S8 z/ A) D4 N

, P; p. o/ Q  ^2 P6 j# r4 g2 X& R"SOCIALTWI*T"
5 x+ q  C" B9 w
% P# H1 K5 v: P! l& Q4 JReturns: "SOCIALTWIST" . C7 ~, S' B/ ~0 U
; J. Z: r+ |8 N6 v6 b3 N3 m# K$ N8 r
1) 3 ^0 D9 {! O, O/ m3 v% B
7 G3 n  b" l% ^
"HELLO*" ( W+ ^. h4 q. |: ~3 i

1 R* _$ M4 ^  `6 W"HI*" . ]& ]  Q/ n- R- j. M6 d; C8 z

/ h# }4 ?5 }5 e+ B. c; U4 wReturns: "not-possible"
7 c# c* T: T; h- m) ~" _9 C; @
3 f9 D+ A# S! O# Q, {, M1 `# n; P! }2)
6 I7 `& j) `# M& M  k4 M: ?* x4 \* d  K- q( b/ e
"PROFESS*" % i3 E) @5 k0 A( K, T! p
; T0 @3 S" L. v! I4 n
"*PROFESS" % |! [# J( ^4 G6 I1 u( g) ~! W
6 ^9 ?6 K3 k7 r$ X6 e
Returns: "PROFESS"
  M- ^! D: L) G  T* ~) M% u
, D2 r/ X+ l! h& x3) 7 r. i0 m1 o. s" N/ {0 n! [2 k  r
! c7 d0 q! \, d* m- i
"*EXAMPLETEST"
: Z: [; i/ [$ K+ T0 [2 E& F
2 o; r. x& c6 ~1 Y" U2 [3 K$ q"THIRDEXAMPLE*"
: c' n$ g# n2 V: W- @5 G
2 [; ?) _" K; lReturns: "THIRDEXAMPLETEST"
# J  P+ v, Y7 |6 F
. h" s: a) \; r4 @$ c4) - }$ g$ P- v( u/ d" }
- l4 v2 @5 k# Z* V# z# X
"*TELL"
0 w1 |- ?  @$ o. ~, I# w( {& ]+ p0 F5 M% U, c$ W
"*AFRIEND"
( e( b1 ]9 k8 x& D' {2 z) X* R: O9 i
9 J- b; [- N: D4 V5 ^0 {2 oReturns: "not-possible" 9 I) P$ f7 x0 ?! |3 E! B

$ ?: y8 d# C) K8 g0 o5)
( X$ I0 z6 B7 T4 _: e0 {/ b; t5 ^" b) a) o$ [, _
"*"
0 y) G7 E6 g* j- k" `( u5 K
4 ]5 R& y  \7 T! K! _: j: g"B*"
+ l$ C- P, u' X8 L6 ?
. W& b# L# g7 C6 L5 ^. ]' bReturns: "B" & L' X2 x9 ?+ J/ G8 q3 g

9 w; A3 g7 s3 V4 B6) 4 c/ V# }6 U/ O% v
) B+ }$ X6 ?; x1 @
"*C"
% {' C) j% _9 D5 i/ U6 R. X5 ^$ V. l* @3 j* q
"D*" 0 ]8 q2 b6 \+ L, d
- ]8 E# O6 [2 w! A4 C% k
Returns: "DC"
$ w, e) r2 N7 X; L1 T
$ m: r  C( V5 M& I( xprogram should be written in java
1 p8 A' L* Q" e3 D+ R2 ], Y
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表