Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- class dep{
- public:
- dep();
- friend std::ostream& operator<< (std::ostream &out, const dep &DEP);
- friend std::istream& operator>> (std::istream &in, dep &DEP);
- void print();
- char* gets_fam(){return s_fam;}
- char* getnumb_of_dep(){return numb_of_dep;}
- double get_income(){return income;}
- double get_outcome(){return outcome;}
- ~dep();
- dep(const dep &DEP);
- dep& operator= (const dep &DEP);
- dep(char* init1,char* init2,double init3, double init4);
- private:
- double income;
- double outcome;
- char* numb_of_dep;
- char* s_fam;
- };
- dep :: dep()
- { s_fam=NULL;
- numb_of_dep=NULL;
- income=0;
- outcome=0;
- }
- dep::dep(char* init1,char* init2,double init3, double init4):
- numb_of_dep(new char[strlen(init2)+1]),s_fam(new char[strlen(init1)+1])
- {
- strcpy( s_fam,init1);
- strcpy(numb_of_dep,init2);
- income =init3;
- outcome =init4;
- }
- ostream& operator<< (ostream &out, const dep &DEP)
- {
- out << DEP.s_fam<<" "<<DEP.numb_of_dep<<" "<<DEP.income<<" "<<DEP.outcome<<endl;
- return out;
- }
- istream& operator>> (istream &in, dep &DEP)
- {
- char buff1[100];
- char buff2[100];
- in >> buff1 >> buff2 >> DEP.income >> DEP.outcome;
- delete[] DEP.s_fam;
- delete[] DEP.numb_of_dep;
- int n=strlen(buff1);
- int l=strlen(buff2);
- DEP.s_fam=new char[n+1];
- DEP.numb_of_dep=new char[l+1];
- strcpy(DEP.gets_fam(),buff1);
- strcpy(DEP.numb_of_dep,buff2);
- return in;
- }
- dep& dep::operator= (const dep &DEP)
- {
- if (this == &DEP)
- return *this;
- income=DEP.income;
- outcome=DEP.outcome;
- delete[] numb_of_dep;
- numb_of_dep=new char[strlen(DEP.numb_of_dep)+1];
- strcpy(numb_of_dep,DEP.numb_of_dep);
- delete[] s_fam;
- s_fam=new char[strlen(DEP.numb_of_dep)+1];
- strcpy(s_fam,DEP.s_fam);
- return *this;
- }
- dep::dep(const dep &DEP):
- numb_of_dep(new char[strlen(DEP.numb_of_dep)+1]),s_fam(new char[strlen(DEP.s_fam)+1])
- {
- income=DEP.income;
- outcome=DEP.outcome;
- strcpy(numb_of_dep,DEP.numb_of_dep);
- strcpy(s_fam,DEP.s_fam);
- }
- dep::~dep(){
- delete [] s_fam;
- delete [] numb_of_dep;
- }
- struct max_value{
- char fam[40];
- double money;
- };
- bool comp(max_value k,max_value b){
- if (k.money>b.money)
- return true;
- return false;
- }
- int main(){
- dep s;
- cin>>s;
- s=s;
- cout<<s;
- setlocale(LC_ALL, "rus");
- int n;
- cin>>n;
- dep k[30];
- for(int i=0;i<n;i++){
- cin>> k[i];
- }
- max_value q[100];
- int f=1;
- strcpy(q[0].fam,k[0].gets_fam());
- q[0].money=k[0].get_income()-k[0].get_outcome();
- for(int i=1;i<n;i++){
- bool flag=0;
- for(int j=0;j<f;j++ ){
- if(! strcmp( k[i].gets_fam(),q[j].fam)){
- q[j].money+=k[i].get_income()-k[i].get_outcome();
- flag=1;
- }
- }
- if(!flag){
- strcpy(q[f].fam,k[i].gets_fam());
- q[f].money=k[i].get_income()-k[i].get_outcome();
- f++;
- }
- }
- sort(begin(q),end(q),comp);
- for(int i=0;i<f;i++){
- cout<<q[i].fam<<" "<<q[i].money<<endl;}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement