读入坐标文件输出坐标距离

#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
using namespace std;
int dis;
int main()
{
    ifstream infile("zuobiao.txt");
    int x,y;
    vector<int> b;
    vector<int> c;

    while(!infile.eof())
    {
        infile>>x>>y;
        b.push_back(x);
        c.push_back(y);
    }
    cout<<b.size()<<endl;
	//int b[]={0, 649, 971, 164, 773, 747, 260, 163, 576, 765, 397, 586, 963, 414, 441, 247, 637, 956, 384, 414, 414};
	//int c[]={0, 766,  81, 681, 419, 890,  50, 188, 681,  37,  20, 713, 567, 458, 935, 115, 132, 967, 364, 458, 458};

	ofstream outfile("distance.txt");
	//ofstream outfile("distance.txt");
	for(int i=0;i<b.size();i++)
	{
		for(int j=0;j<b.size();j++)
		{
			dis=sqrt((b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
			//dis=abs(b[i]-b[j])+abs(c[i]-c[j]);
//			if(i!=j && dis==0)
//			{
//				outfile<<0.001<<" ";
//			 }
//			 else
//			 {
			 	outfile<<dis<<" ";
//			  }

		}
		outfile<<endl;
	}


	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值