Skip to content

Commit 7dec50d

Browse files
committed
Added 1676C - Most Similar Words.cpp
1 parent 086ea11 commit 7dec50d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

1676C - Most Similar Words.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
// Code Written By: Vikash Patel
5+
6+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
7+
8+
int strDiff(string x, string y)
9+
{
10+
int sum = 0;
11+
for (int i = 0; i < x.size (); i++)
12+
{
13+
sum += abs (x[i] - y[i]);
14+
}
15+
return sum;
16+
}
17+
18+
int main()
19+
{
20+
int t;
21+
cin >> t;
22+
while (t--)
23+
{
24+
int n, m;
25+
cin >> n >> m;
26+
string s[n];
27+
for (int i = 0; i < n; i++)
28+
{
29+
cin >> s[i];
30+
}
31+
int mini = INT_MAX;
32+
for (int i = 0; i < n; i++)
33+
{
34+
for (int j = 0; j < n; j++)
35+
{
36+
if (i != j)
37+
mini = min (mini, strDiff (s[i], s[j]));
38+
}
39+
}
40+
cout << mini << endl;
41+
}
42+
}

0 commit comments

Comments
 (0)