首页 > 试题广场 >

字符串中找出连续最长的数字串

[编程题]字符串中找出连续最长的数字串
  • 热度指数:41554 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
读入一个字符串str,输出字符串str中的连续最长的数字串

输入描述:
个测试输入包含1个测试用例,一个字符串str,长度不超过255。


输出描述:
在一行内输出str中里连续最长的数字串。
示例1

输入

abcd12345ed125ss123456789

输出

123456789
头像 牛客455901501号
发表于 2021-09-26 21:12:20
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Strin 展开全文
头像 白伟仝
发表于 2020-07-24 21:05:50
用split按字母分开: import java.util.*; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(Sys 展开全文
头像 aBDK
发表于 2022-09-13 16:09:58
import java.util.*; public class Main{     public static void main(String arg[]){         //输入字符串       展开全文
头像 牛马ID
发表于 2022-05-28 16:34:57
#include <iostream> #include <string> using namespace std; bool isNumb(char c){ return c <= '9' && c >= '0'; } int m 展开全文
头像 牛客492517985号
发表于 2023-05-20 12:56:12
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = 展开全文
头像 牛客427561930号
发表于 2022-04-26 21:19:21
#题比较简单,如果给出的数字不是顺序的,就会比较麻烦 import re, bisect w = re.findall(r'\d+', input()) n = list(map(int, w)) print(max(n))
头像 TheXLg
发表于 2022-09-11 18:40:57
用转成ascll码解题 const line = readline(); let arr = line.split('').map(item=>item.charCodeAt()); let map = new Map() let count= 0; let str = ''; let old 展开全文
头像 小浪学编程
发表于 2022-11-23 18:03:27
将字符放在数组里面 判断数字存入数组然后计算数组长度 import java.util.Scanner; public class Main { /** * 连续最长数字串 * * @param args */ public static 展开全文
头像 梁寒郡
发表于 2022-10-10 19:13:30
#include <iostream> #include <vector> using namespace std; int main() {  &nbs 展开全文
头像 牛客327297870号
发表于 2022-11-11 20:34:41
import re ss = input() ll1 = re.split('[a-z]| ',ss) ll2 = list(map(len,ll1)) print(ll1[ll2.index(max(ll2))])