赞
踩
题目描述
请一个在字符串中找出连续最长的数字串,并把这个串的长度返回;如果存在长度相同的连续数字串,返回最后一个连续数字串;
注意:数字串只需要是数字组成的就可以,并不要求顺序,比如数字串“1234”的长度就小于数字串“1359055”,如果没有数字,则返回空字符串(“”)而不是NULL!(说明:不需要考虑负数)
输入描述:
字符串
输出描述:
连续数字串&在所有数字串最长的长度
示例1
输入
abcd12345ed125ss123058789
输出
123058789
9
#include <iostream>
#include <string>
#include <algorithm>
#include <ctype.h>
bool legal( char ch ) { return isdigit(ch); }
bool illegal( char ch ) { return !legal(ch); }
void resolve_line( std::string& line, std::string& pat );
int main(void){
std::string line;
while(std::cin >> line){
std::string ans = "";
resolve_line(line, ans);
if(ans != ""){
std::cout << ans << std::endl

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。