C拼图 [英] C puzzle

查看:113
本文介绍了C拼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



给定一个字符串s1和一个字符串s2,写一个片段来说明s2

是否仅仅使用了s1的
轮换一次调用strstr例程?


(例如,给定s1 = ABCD和s2 = CDAB,返回true,

给定s1 = ABCD,s2 = ACBD,返回false)

解决方案

deepak说:


>

给定一个字符串s1和一个字符串s2,写一个片段,说明s2

是否仅使用一次调用strstr的s1转换为
常规?



肯定那是'你的工作?


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。


您好,


给定一个字符串s1和一个字符串s2,写一个片段,说明s2

是否仅使用一次调用strstr例程的s1旋转




(例如,给定s1 = ABCD和s2 = CDAB,返回true,

给定s1 = ABCD,s2 = ACBD,返回false)



这并不是很复杂。一个可能的算法包括:


1)找到n,这样s2 [n] == s1 [0]

2)构建一个临时字符串y这是s2旋转了n个位置。

3)比较s1和y。


干杯,

Loic。



lo ****** @ gmx。 net 写道:


你好,


给定一个字符串s1和一个字符串s2,只用一次调用strstr例程,写一个片段来说明是否s2

是s1的旋转?


(例如给定s1 = ABCD且s2 = CDAB,返回true,

给定s1 = ABCD,s2 = ACBD,返回false)



并不是很复杂。一个可能的算法包括:


1)找到n,这样s2 [n] == s1 [0]

2)构建一个临时字符串y这是s2旋转n个位置。

3)比较s1和y。



如果
$ b这可能不起作用$ b s1 = ABCADE和s2 = CADEAB

s2 [n] = A,其中n = 1.临时字符串y = ADEABC。

s1比较不等于y。

我的意思是说你的算法会失败,如果字符串s2中有多个s1 [0]





Given a string s1 and a string s2, write a snippet to say whether s2
is a
rotation of s1 using only one call to strstr routine?

(eg given s1 = ABCD and s2 = CDAB, return true,
given s1 = ABCD, and s2 = ACBD , return false)

解决方案

deepak said:

>
Given a string s1 and a string s2, write a snippet to say whether s2
is a
rotation of s1 using only one call to strstr routine?

Surely that''s your job?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


Hello,

Given a string s1 and a string s2, write a snippet to say whether s2
is a
rotation of s1 using only one call to strstr routine?

(eg given s1 = ABCD and s2 = CDAB, return true,
given s1 = ABCD, and s2 = ACBD , return false)

This is not really complicated. A possible algorithm consists to:

1) Find n, such that s2[n] == s1[0]
2) Build a temporary string y which is s2 rotated of n positions.
3) Compare s1 and y.

Cheers,
Loic.



lo******@gmx.net wrote:

Hello,

Given a string s1 and a string s2, write a snippet to say whether s2
is a
rotation of s1 using only one call to strstr routine?

(eg given s1 = ABCD and s2 = CDAB, return true,
given s1 = ABCD, and s2 = ACBD , return false)


This is not really complicated. A possible algorithm consists to:

1) Find n, such that s2[n] == s1[0]
2) Build a temporary string y which is s2 rotated of n positions.
3) Compare s1 and y.

This may not work if
s1 = ABCADE and s2 = CADEAB
s2[n] = A, where n = 1. temporary string y = ADEABC.
s1 compares not equal to y.
I mean to say your algorithm will fail, if there is more than one s1[0]
in string s2.


这篇关于C拼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆