编写程序以查找数字中最大的增加序列 [英] Write a program to find the largest increasing sequence in a number

查看:98
本文介绍了编写程序以查找数字中最大的增加序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个数字

Eg1:11261234在这个数字中最大的序列是1234

Eg2:4712389在这个数字中最大的序列是123



我尝试了什么:



没什么......我什么都不懂

Consider a number
Eg1: 11261234 In this number the largest sequence is 1234
Eg2: 4712389 In this number the largest sequence is 123

What I have tried:

Nothing...i didn't understand anything

推荐答案

这是你的作业,所以我们不会给你任何代码。



但这个如果你坐下来思考它并不复杂。首先要弄清楚如何手动完成。

您将从左到右查看序列中的每个字符,并查看它是否是序列的开头。如果是的话,你不会在它开始的地方,以及它的长度,然后你跳过序列并继续寻找另一个。

如果你找到另一个,你会做同样的事情,但你决定哪个是最长的,丢弃另一个。

如果你没找到另外,你有最长的保存时间,这就是你想要的。



手动试试,你会明白我的意思。



现在你需要做的就是编写代码:一旦你弄清楚要做什么就很容易!



试一试,看看你能走多远。
This is your homework, so we aren't going to give you any code.

But this isn't complicated, if you sit down and think about it. Start by working out how you would do it manually.
You would look at each character in the sequence from left to right, and seeing if it is the beginning of a sequence. If it is, you'd make a not of where it starts, and how long it is, then you'd skip the sequence and continue looking for another.
If you found another, you'd do the same thing, but you'd decide which is the longest, and discard the other.
If you didn't find another, you'd have the longest saved, so that's what you wanted.

Try that manually, and you'll see what I mean.

Now all you have to do is code to do that: and that's pretty easy once you've worked out what to do!

Give it a try, and see how far you get.


Google [ ^ ]是你的朋友!



Google返回的第一个结果是:增长最快的子序列。·GitHub [ ^ 。您可以通过分析代码来学习。
Google[^] is your firend!

First result returned by Google is: longest-increasing-subsequence.c · GitHub[^]. You can learn by analyze code.


从一些 C教程开始学习使用语言尤其是字符串,并安装像Visual Studio这样的IDE。



通过检查所有子序列找到的最长序列。您需要构建子字符串并进行比较。
Start with some C tutorial to learn the usage of the language especially strings and install an IDE like Visual Studio.

The longest sequence you find by checking all sub-sequences. You need to build sub-strings and compare them.


这篇关于编写程序以查找数字中最大的增加序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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