67 lines
1002 B
C++
67 lines
1002 B
C++
|
#include <iostream>
|
||
|
#include <vector>
|
||
|
#include <string>
|
||
|
#include <fstream>
|
||
|
#include <algorithm>
|
||
|
using namespace std;
|
||
|
|
||
|
class Student{
|
||
|
public:
|
||
|
string nume, prenume, grupa;
|
||
|
string stringify(){
|
||
|
return nume+" "+prenume+" "+grupa;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
bool studentCompare(const Student a, const Student b){
|
||
|
if(a.nume == b.nume){
|
||
|
if(a.prenume <= b.prenume){
|
||
|
return true;
|
||
|
}
|
||
|
else{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
else if(a.nume <= b.nume){
|
||
|
return true;
|
||
|
}
|
||
|
else{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(){
|
||
|
ios::sync_with_stdio(false);
|
||
|
|
||
|
fstream f;
|
||
|
|
||
|
f.open("an.txt", ios_base::in);
|
||
|
if(!f.is_open()){
|
||
|
cout<<"Error: file does not exist";
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
vector<Student> v;
|
||
|
|
||
|
string buff;
|
||
|
while(f>>buff){
|
||
|
Student tmp;
|
||
|
tmp.nume = buff;
|
||
|
f>>tmp.prenume;
|
||
|
f>>tmp.grupa;
|
||
|
v.push_back(tmp);
|
||
|
}
|
||
|
f.close();
|
||
|
|
||
|
sort(v.begin(), v.end(), studentCompare);
|
||
|
|
||
|
f.open("an_sort.txt", ios_base::out);
|
||
|
for(vector<Student>::iterator it = v.begin(); it < v.end(); it++){
|
||
|
f<<it->stringify();
|
||
|
f<<"\n";
|
||
|
}
|
||
|
f.close();
|
||
|
|
||
|
return 0;
|
||
|
}
|