-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathb.cpp
52 lines (49 loc) · 1.06 KB
/
b.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
#include <bits/stdc++.h>
using namespace std;
string rev(string s){
for(int i = 0; i < s.length() / 2; i++){
swap(s[i], s[s.length() - 1 - i]);
}
return s;
}
int main(){
int N, M;
cin >> N >> M;
string s[N];
for(int i = 0; i < N; i++){
cin >> s[i];
}
int ret = 0;
string center = "";
for(int i = 0; i < N; i++){
if(s[i] == rev(s[i])){
ret++;
center = s[i];
break;
}
}
vector<string> out;
for(int i = 0; i < N; i++){
for(int j = i + 1; j < N; j++){
if(s[i] == rev(s[j])){
ret += 2;
out.push_back(s[i]);
break;
}
}
}
cout << ret * M << endl;
if(out.size() != 0){
for(int i = 0; i < out.size(); i++){
cout << out[i];
}
cout << center;
for(int i = out.size() - 1; i > 0; i--){
cout << rev(out[i]);
}
cout << rev(out[0]) << endl;
}else{
cout << center << endl;
}
return 0;
}