-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (37 loc) · 1008 Bytes
/
main.cpp
File metadata and controls
38 lines (37 loc) · 1008 Bytes
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
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<string> vect;
int number_of_items, length;
cin >> number_of_items >> length;
for (int i = 0; i < number_of_items; i++) {
string x;
cin >> x;
vect.push_back(x);
}
sort(vect.begin(), vect.end());
int cnt = 0;
vector<int> counter;
for(int index = 0; index < number_of_items-1; index++) {
int common = 0;
for(int char_index = 0; char_index < length; char_index++) {
if(vect[index][char_index] == vect[index+1][char_index]) {
common++;
} else {
common++;
break;
}
}
counter.push_back(common);
}
cnt+=counter[0];
cnt+=counter[number_of_items-2];
for(int index = 1; index < number_of_items-1; index++) {
cnt += max(counter[index-1], counter[index]);
}
cout << cnt << '\n';
return 0;
}