-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontinumax.cpp
More file actions
67 lines (61 loc) · 1.14 KB
/
continumax.cpp
File metadata and controls
67 lines (61 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
#include <ctype.h>
#include <string.h>
using namespace std;
int continumax(char ** outputStr, char * inputStr)
{
char last = 0;
char * startStr = inputStr;
char * maxStr;
int count = 0;
int maxCount = 0;
while(*inputStr != '\0')
{
if(isdigit(*inputStr))
{
if(!isdigit(last) || *inputStr != (last+1))
{
if(count > maxCount)
{
maxStr = startStr;
maxCount = count;
}
startStr = inputStr;
count = 1;
}
else
{
count++;
}
}
else if(isdigit(last))
{
if(count > maxCount)
{
maxStr = startStr;
maxCount = count;
}
}
last= *inputStr;
inputStr++;
}
if(count > maxCount)
{
maxStr = startStr;
maxCount = count;
}
*outputStr = maxStr;
return maxCount;
}
int main(void)
{
const char * c_str = "abcd12345ed125ss123456789";
char * str = new char [128];
char * output = NULL;
strcpy(str, c_str);
cout << continumax(&output, str)<<endl;
cout << strlen(output)<<endl;
delete [] str;
return 0;
}