, . , . , ( ).
#include<iostream>
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include <stdlib.h>
#include<windows.h>
#include <fstream> //
using namespace std; //!!!
//
void swap(float& a, float& b)
{
float tmp;
tmp=a; a=b; b=tmp;
}
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
// :
ifstream inf("test.txt");
ofstream outf("sort.txt");
int m,n; //
register int i,j;
// ( )
inf >> m >> n;
/* , */
float *vek, **mat;
/* . , */
vek=new float[m*n]; //
mat=new float*[m];
//
for (i=0; i<m; i++) //
mat[i]= &vek[i*n]; //
printf(" :\r\n");
//
for (i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
inf>>mat[i][j];
//
if (inf.eof())
// ,
{
printf(" \r\n");
_getch();
exit(0);
}
printf("%10.2f",mat[i][j]); //
}
printf("\r\n"); //
}
// :
for (j=0; j<n; j++) //
for (int p=1; p<m; p++) //
for (i=0; i<m-p; i++)
//
if (mat[i][j]>mat[i+1][j])
swap (mat[i][j],mat[i+1][j]);
// , ,
// :
cout << " : \n";
for (i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
// :
outf <<setiosflags(ios::showpoint)<< setprecision(2)<<setw(10)<<mat[i][j];
|
|
// :
cout <<setiosflags(ios::showpoint) << setprecision(2)<< setw(10)<<mat[i][j];
// 8
}
outf<<endl;
//
cout << endl;
}
outf.close();
delete []mat;
delete []vek;
_getch();
return 0;
}
6. , .
, , ( ), . , . , .
#include<iostream>
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include <stdlib.h>
#include<fstream>
#include<windows.h>
using namespace std;
// , :
struct stroka
{
long pos; // ,
int len; //
};
// :
template <class Type> void swapq(Type &a, Type &b)
/* ( )*/
{
Type tmp;
tmp=a; a=b; b=tmp;
}
// :
void qusort(stroka *mas, int left, int right)
{
/*: , , */
register int i,j; //
int x;
i=left; j=right;
x=mas[(left+right) / 2].len; //
do //
{
while(mas[i].len < x && i < right) i++;
// , X
while(mas[j].len > x && j > left) j--;
// , X
if (i <= j)
{
// :
swapq<stroka>(mas[i], mas [j]);
i++; j--;
}
} while (i <= j);
/* 2 : X, */
/* : */
if (left < j) qusort(mas, left, j);
if (i < right) qusort(mas, i, right);
}
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
// :
ifstream inf;
char *name=new char[81]; //
do //
{
cout<<" <Esc>";
cout<<" ";
name[0]=_getche(); //
if (name[0]==27) exit(0);
// <Esc>,
cin.getline(&name[1],80);
//
inf.open(name); //
if (!inf)
|
|
cout<<" ! \n";
} while(!inf); /* , */
/* , */
fstream outf("rez.txt",ios::out);
//
char *str=new char[102]; //
char *beg=str; //
// :
int kol=0;
while (!inf.eof())
{
inf.getline(str,102);
kol++;
}
// :
stroka *mas = new stroka[kol];
inf.clear();
inf.seekg(0l,ios::beg);
mas[0].pos=0; //
int l; //
// :
for (int i = 0; i < kol; i++)
{
str = beg;
/* str, str , */
inf.getline(str,102); //
l=strlen(str);
if (i < kol-1) //
{
mas[i+1].pos=inf.tellg();
//
while (*str == ' ' || *str == 9)
{
str++;
mas[i].pos++;
} //
}
mas[i].len = strlen(str);
//
}
// :
qusort(mas,0,kol-1);
// , , :
inf.clear();
for (int i = 0; i < kol; i++)
{
if (inf.eof()) inf.clear();
//
inf.seekg(mas[i].pos, ios::beg);
inf.getline(str,102); //
if (*str) outf<<str<<endl;
//
}
outf.close();
cout<<" \"rez.txt\"";
_getch();
return 0;
}