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;
}