#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<algorithm>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
void main()
{
string s1;
ifstream fin("aaa.txt");
ofstream fout1("bjc.txt");
ofstream fout2("px.txt");
ofstream fout3("max.txt");
if(fin)
{
double ave,s;
int line=0;
VI vi;
VVI vvi;
for(;getline(fin,s1);)
{
line++;
vi.clear();
cout<<s1<<endl;
istringstream iss(s1);
int num,sum=0,i=0,j=0; double sum2=0;
for(;iss>>num;)
{
vi.push_back(num);
sum+=num;i++;
}
vvi.push_back(vi);
ave=1.0*sum/i;
for(i=0;i<vi.size();i++)
sum2 += 1.0 * (vi[i]-ave)*(vi[i]-ave);
s=sqrt(sum2/vi.size());
cout<<"ave="<<ave<<"\n"<<"方差="<<s<<"\n"<<endl;
fout1<<s<<endl;//写入标准差
}
/*向量排序*/
for(int i=0;i<vvi.size()-1;i++)
for(int j=0;j<vvi.size()-1-i;j++)
if(vvi[j].size()>vvi[j+1].size())
vvi[j].swap(vvi[j+1]);
for(int i=0;i < vvi.size();i++)
{
for(int j=0;j< vvi[i].size();j++)
{
cout<<vvi[i][j]<<' ';
fout2<<vvi[i][j]<<' ';
}
fout2<<endl;
cout<<endl;
}
/*写入最大值*/
for(int j=0;j<vvi.size();j++)
{
int max=0;
for(int i=0;i<vvi[j].size();i++)
{
if(max<vvi[j][i])
max=vvi[j][i];
}
fout3<<max<<endl;
}
}
else
cout<<"can not read file!\n";
}
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)