Huawei oj--to find the longest consecutive number string in strings

Source: Internet
Author: User

To find the longest consecutive number of string problem descriptions in strings

Sample output

Output 123058789, function return value 9

Output 54761, function return value 5

Interface description

Function Prototypes:

Unsignedint Continumax (char** poutputstr, char* intputstr)

Input parameters:
char* intputstr input string;

Output parameters:
char** Poutputstr: The longest consecutive number string, if the length of the longest serial number string is 0, should return an empty string; If the input string is empty, you should return an empty string;

return value:
Length Input Description of the longest consecutive number string:

Enter a string. Output Description:

The longest numeric string in the output string and its length. If you have a string of the same length, you output it together, but the length is a string of length input examples:

abcd12345ed125ss123058789 Output Example:

123058789,9

Answer code:

#include <iostream> #include <fstream> #include <string> #include <cstring> #include <

Algorithm> #include <sstream> using namespace std;
    int main () {char s[1024];
        while (Cin.getline (s,1024)) {string temp= "";
        String resu= "";
        int i,max=0,cou=0;
        int flaglength=0;
        int Length=strlen (s);
                For (i=0 i<length; i++) {if (s[i) >= ' 0 ' && s[i] <= ' 9 ') {
                cou++;
            Temp+=s[i];
                    } else {if (Cou>max) {resu=temp;
                    Max=cou;
                    Temp= "";
                    cou=0;
                Continue
                else if (Max==cou) {resu+=temp;
                } temp= "";
            cou=0;
  } if (I==length) {          if (Cou>max) {resu=temp;
                Temp= "";
                Max=cou;
            cou=0;
        else if (Cou==max) resu+=temp;
    } cout<<resu<< ', ' <<max<<endl;
return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.