-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
74 lines (73 loc) · 1.9 KB
/
test.cpp
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
68
69
70
71
72
73
74
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> dt;
while (n / 10 != 0)
{
dt.push_back(n % 10);
n = n / 10;
}
dt.push_back(n);
vector<int> begin_index;
int len = 1;
for (int i = 0; i < dt.size(); i++)
{
for (int bias = 1; i - bias >= 0 && i + bias < dt.size(); bias++)
{
if (dt[i - bias] != dt[i + bias])
{
int sub_len = 2 * bias - 1;
int begin = i - bias + 1;
if (sub_len > len)
{
len = sub_len;
begin_index.clear();
begin_index.push_back(begin);
}
else if (sub_len == len)
{
begin_index.push_back(begin);
}
break;
}
}
if (i < dt.size() - 1 && dt[i] == dt[i + 1])
{
for (int bias = 1; i - bias >= 0 && i + 1 + bias < dt.size(); bias++)
{
if (dt[i - bias] != dt[i + 1 + bias])
{
int sub_len = 2 * bias;
int begin = i - bias + 1;
if (sub_len > len)
{
len = sub_len;
begin_index.clear();
begin_index.push_back(begin);
}
else if (sub_len == len)
{
begin_index.push_back(begin);
}
break;
}
}
}
}
for (int i = 0; i < begin_index.size(); i++)
{
int begin = begin_index[i];
for (int j = 0; j < len; j++)
{
cout << dt[begin + j] << " ";
}
cout << endl;
}
getchar();
getchar();
return 0;
}