可能你的最外层循环写成了
for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i==j)continue; ... } }
应该改成
for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ ... } }