请问这里为什么输出的顺序不一样
#include <iostream>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include<cmath>
#include <algorithm>
#include <math.h>
using namespace std;
struct research{
char name[13];
int x;
int y;
char kind[10];
};
int heng,zong;
int cmp(research a, research b ){
if(((a.x-heng)*(a.x-heng)+(a.y-zong)*(a.y-zong))!=((b.x-heng)*(b.x-heng)+(b.y-zong)*(b.y-zong)))
return ((a.x-heng)*(a.x-heng)+(a.y-zong)*(a.y-zong))<((b.x-heng)*(b.x-heng)+(b.y-zong)*(b.y-zong));
return(strcmp(a.name,b.name));
}
int main()
{
int n,m;
cin>>n>>m;
struct research a[n];
for(int i=0;i<n;i++)
{
cin>>a[i].name>>a[i].x>>a[i].y>>a[i].kind;
}
int k;
int cnt;
int flag=0;
for(int i=0;i<m;i++)
{ cnt=0;
char want[10];
cin>>heng>>zong;
cin>>want;
cin>>k;
sort(a,a+n,cmp);
for(int j=0;j<n&&cnt<k;j++)
{
if(strcmp(a[j].kind,want)==0)
{ flag=1;
cnt++;
double dis=sqrt(((double)a[j].x-(double)heng)*((double)a[j].x-(double)heng)+((double)a[j].y-(double)zong)*((double)a[j].y-(double)zong));
cout<<a[j].name<<' ';
printf("%.3f\n",dis);
}
}
if(!flag) cout<<endl;
}
}