Because not on the intranet, your own hands to lay the problem. The meaning is like this: input an n, for n boys, below is the number of N, representing each boy's ability to dance. Enter a m for M girls, below is the number of M, representing each girl's ability to dance. Now to start pairing (must be paired with each other), the principle of pairing is that men and women cannot dance more than one value. Ask how many pairs there are. Case has been forgotten. I'm directly on the code. Have resolved
#include <stdio.h> #include <math.h> #include <string.h> #include <algorithm>using namespace Std;int Main () {int n,m,i,j,sum,k;double a[105];d ouble b[105];while (~scanf ("%d", &n)) //Enter n males {for (i=0;i< n;i++) scanf ("%lf", &a[i]);//input n male capacity value scanf ("%d", &m), for (i=0;i<m;i++) scanf ("%lf", &b[i]);//ditto sort (a,a+n);//Sort (b,b+m) the ability value,//the same as sum=0;//sum on the outside. Otherwise, the pairing is not allowed, for (i=0;i<n;i++) {for (j=0;j<m;j++) {if (Fabs (A[i]-b[j]) <=1.0)// if paired {b[j]=-232;// The ability value of the paired girl is assigned a negative number so that she will not be paired again. (Here is the key to solving the problem) sum++; Break;}}} printf ("%d", sum); Output}return 0;}
Seniors out of the problem.