如何查找给定字符串的所有子字符串 [英] How to find all substrings of a given string

查看:114
本文介绍了如何查找给定字符串的所有子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要了解如何接近!!!



我尝试过的事情:



Nope !!

我不知道!!

不要不怎么接近它并开始使用!!

I just need an idea about how to approach!!!

What I have tried:

Nope!!
I’m having no idea!!
Don’t no how to approach for it and get started!!

推荐答案

Quote:

如何查找给定字符串的所有子字符串

How to find all substrings of a given string



用一张纸和一支铅笔,你得到类似的东西:

- imput string =abcdef

- 子串: aababcabcdabcdeabcdefbbcbcdbcdebcdefccdcdecdefdde defeeff

- 查找哪些操作按顺序给出子串,以及其中2个之间的变化。

- 演绎算法和编写代码。



我们不做你的家庭作业。

HomeWork不会在乞求别人的时候测试你的技能做你的工作,它会让你思考并帮助你的老师检查您对所学课程的理解以及您应用这些课程时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。


With a sheet of paper and a pencil, you get something like:
- imput string= "abcdef"
- substrings: "a" "ab" "abc" "abcd" "abcde" "abcdef" "b" "bc" "bcd" "bcde" "bcdef" "c" "cd" "cde" "cdef" "d" "de" "def" "e" "ef" "f"
- find which operations give the substrings in order and what are the changes between 2 of them.
- deduce the algorithm and write code.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.


递归。

如果你不'知道递归,然后看看递归(计算机科学) - 维基百科 [ ^ ]。


蛮力方法会是使用两个循环。



外循环从0变为len-1,

内循环从outer-loop-var变为len-1

使用两个循环变量作为开始和结束索引提取子字符串(使用strncpy)



这应该适用于任何语言,你的选择似乎是C.
A brute force approach would be to use two loops.

outer loop goes from 0 to len-1,
inner loop goes from outer-loop-var to len-1
extract substring using the two loop variables as start and end index (use strncpy)

This should work in any language, and your choice seems to be C.


这篇关于如何查找给定字符串的所有子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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