描述
读入一个字符串str,输出字符串str中的连续最长的数字串
输入描述:
个测试输入包含1个测试用例,一个字符串str,长度不超过255。
输出描述:
在一行内输出str中里连续最长的数字串。
示例1
输入:
abcd12345ed125ss123456789
输出:
123456789
解题思路
正则,o( ̄︶ ̄)o
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
let params = []
while(line = await readline()){
let tokens = line.split(' ');
// let a = parseInt(tokens[0]);
// let b = parseInt(tokens[1]);
// console.log(a + b);
params.push(tokens)
}
// console.log(params)
let str = params[0][0]
let matches = str.matchAll(/[0-9]+/g)
let maxStr = ""
for(match of matches){
// console.log(match)
let str = match[0]
if(str.length > maxStr.length){
maxStr = str;
}
}
console.log(maxStr)
}()