Posted on 2009-03-18 17:54
superman 阅读(99)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 freopen("calfflac.in", "r", stdin);
8 freopen("calfflac.out", "w", stdout);
9
10 string oristr;
11 string newstr;
12 int pos[20002];
13
14 while (true)
15 {
16 char c = getchar();
17 if (c == EOF)
18 break;
19 else
20 oristr += c;
21 }
22
23 for (int i = 0, n = 0; i < oristr.size(); i++)
24 if (isalpha(oristr[i]))
25 newstr += tolower(oristr[i]), pos[n++] = i;
26
27 int ans_len = 0;
28 int ans_pos = 0;
29 for (int k = 0; k < newstr.size(); k++)
30 {
31 int i = k, j = k;
32
33 while (i - 1 >= 0 && j + 1 < newstr.size() && newstr[i - 1] == newstr[j + 1])
34 i -= 1, j += 1;
35 if (j - i + 1 > ans_len)
36 {
37 ans_len = j - i + 1;
38 ans_pos = i;
39 }
40
41 if (k + 1 < newstr.size() && newstr[k] == newstr[k + 1])
42 {
43 i = k, j = k + 1;
44 while (i - 1 >= 0 && j + 1 < newstr.size() && newstr[i - 1] == newstr[j + 1])
45 i -= 1, j += 1;
46 if (j - i + 1 > ans_len)
47 {
48 ans_len = j - i + 1;
49 ans_pos = i;
50 }
51 }
52 }
53
54 cout << ans_len << endl;
55 for (int i = pos[ans_pos], n = 0; n < ans_len; i++)
56 {
57 cout << oristr[i];
58 if (isalpha(oristr[i]))
59 n++;
60 }
61 cout << endl;
62
63 return 0;
64 }
65