Skip to content

Instantly share code, notes, and snippets.

@avamsi
Created November 23, 2014 10:47
Show Gist options
  • Select an option

  • Save avamsi/0974e54229aa21891455 to your computer and use it in GitHub Desktop.

Select an option

Save avamsi/0974e54229aa21891455 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int abs(int n)
{
if (n < 0)
return -1 * n;
else
return n;
}
int main()
{
int i, j, t, a[1005], b[1005], la, lb, m;
cin >> t;
while (t--)
{
cin >> la;
for (i = 0; i < la; i++)
cin >> a[i];
cin >> lb;
for (i = 0; i < lb; i++)
cin >> b[i];
m = abs(a[0] - b[0]);
for (i = 0; i < la; i++)
for (j = 0; j < lb; j++)
{
if (abs(a[i] - b[j]) < m)
m = abs(a[i] - b[j]);
}
cout << m << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment