-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
37 lines (36 loc) · 746 Bytes
/
C.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
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
long long t,n,m,i,j,k,ara[100][20],mn;
string s;
cin>>t;
while(t--)
{
cin>>n>>m;
mn=INT_MAX;
for(i=0;i<n;i++)
{
cin>>s;
for(j=0;j<m;j++)
ara[i][j]=(s[j]-'a');
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
long long sum=0;
for(k=0;k<m;k++)
{
sum+=abs(ara[j][k]-ara[i][k]);
}
mn=min(mn,sum);
}
}
cout<<mn<<"\n";
}
return 0;
}