64,701
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <iomanip>
#include<algorithm>
#include <string>
#include <vector>
using namespace std;
class Problem
{
public:
Problem();
int GetGrade();
static void SetPunish();
private:
int accept_time;
int wrong_times;
static int punish;
};
Problem::Problem()
{
int temp;
cin>>temp;
if(temp<0)
{
this->wrong_times = -temp;
this->accept_time = 0;
}
else
{
if(temp==0)
{
this->wrong_times = 0;
this->accept_time = 0;
}
else
{
this->accept_time = temp;
if( cin.get()=='(')
{
cin>>this->wrong_times;
cin.get();
}
else
{
this->wrong_times = 0;
}
}
}
}
int Problem::GetGrade()
{
if( this->accept_time==0 )
{
return 0;
}
else
{
return this->accept_time + this->wrong_times * this->punish;
}
}
void Problem::SetPunish()
{
cin>>Problem::punish;
}
class Student
{
public:
Student();
void Calculate();
int GetGrade();
int GetAccept();
string& GetName();
void print();
static void SetPeople();
private:
string name;
Problem *questions;
int accept_problem;
int grade;
static int people;
};
Student::Student()
{
cin>>this->name;
this->questions = new Problem[this->people];
this->Calculate();
}
inline string& Student::GetName()
{
return this->name;
}
inline int Student::GetAccept()
{
return this->accept_problem;
}
inline int Student::GetGrade()
{
return this->grade;
}
void Student::Calculate()
{
int i, grade;
this->accept_problem = 0;
this->grade = 0;
for(i = 0; i < this->people; i++)
{
grade = this->questions[i].GetGrade();
if( grade )
{
this->grade += grade;
this->accept_problem += 1;
}
}
}
void Student::SetPeople()
{
cin>>Student::people;
}
bool compare(Student &a,Student &b);
bool compare(Student &a,Student &b)
{
if( a.GetAccept() < b.GetAccept() )
{
return false;
}
if( a.GetAccept() > b.GetAccept() )
{
return true;
}
if( a.GetGrade() < b.GetGrade() )
{
return true;
}
if( a.GetGrade() > b.GetGrade() )
{
return false;
}
if( a.GetName().compare( b.GetName() ) < 0 )
{
return true;
}
else
{
return false;
}
}
void Student::print()
{
cout<<setw(10)<<left<<this->GetName()<<" "<<right<<setw(2)<<this->GetAccept()<<" "<<right<<setw(4)\
<<this->GetGrade()<<endl;
}
int Problem::punish = 0;
int Student::people = 0;
int main()
{
Student *p;
vector<Student>students;
Student::SetPeople();
Problem::SetPunish();
while( cin.peek()!=EOF )
{
p = new Student();
students.push_back(*p);
cin.get();
}
sort(students.begin(),students.end(),compare);
int i = students.size(),j;
for(j = 0; j < i; j++)
{
students[j].print();
}
return 0;
}
#include<iostream>
#include <stdio.h>
#include<cstring>
using namespace std;
struct student
{
char name[10];
int sum;
int temp;
int solved[13];
};
int main()
{
int n,m;
cin>>n>>m;
char b[10];
student a[1000];
int k=0;
while(cin>>b)
{
strcpy(a[k].name,b);
a[k].sum=0;
a[k].temp=0;
for(int i=0;i<n;i++)
{
cin>>a[k].solved[i];
if(a[k].solved[i]>0)
{
a[k].temp+=a[k].solved[i];
a[k].sum++;
}
if(getchar()=='(')
{
int x;
cin>>x;
a[k].temp+=x*m;
getchar();
}
}
k++;
}
for(int i=0;i<k;i++)
{
for(int j=0;j<k-i-1;j++)
if(a[j].sum<a[j+1].sum)
{
student b;
b=a[j],a[j]=a[j+1],a[j+1]=b;
if(a[j].sum==a[j+1].sum)
{
if(a[j].temp>a[j+1].temp)
b=a[j],a[j]=a[j+1],a[j+1]=b;
else if(a[j].temp==a[j+1].temp)
{
if(a[j].name>a[j+1].name)
b=a[j],a[j]=a[j+1],a[j+1]=b;
}
}
}
printf("%-10s %2d %4d\n",a[i].name,a[i].sum,a[i].temp);
}
}
#include <iostream>
#include <iomanip>
#include<algorithm>
#include <string>
#include <vector>
using namespace std;
class Problem
{
public:
Problem();
int GetGrade();
static void SetPunish();
private:
int accept_time;
int wrong_times;
static int punish;
};
Problem::Problem()
{
int temp;
char c;
cin>>temp;
if(temp<0)
{
this->wrong_times = -temp;
this->accept_time = 0;
}
else
{
if(temp==0)
{
this->wrong_times = 0;
this->accept_time = 0;
}
else
{
this->accept_time = temp;
if( (c=cin.get())=='(')
{
cin>>this->wrong_times;
cin.get();
}
else
{
this->wrong_times = 0;
}
}
}
}
int Problem::GetGrade()
{
if( this->accept_time==0 )
{
return 0;
}
else
{
return this->accept_time + this->wrong_times * this->punish;
}
}
void Problem::SetPunish()
{
cin>>Problem::punish;
}
class Student
{
public:
Student();
void Calculate();
int GetGrade();
int GetAccept();
string& GetName();
void print();
static void SetPeople();
private:
string name;
Problem *questions;
int accept_problem;
int grade;
static int people;
};
Student::Student()
{
cin>>this->name;
if (!this->name.empty())//加
{
this->questions = new Problem[this->people];
this->Calculate();
}
}
inline string& Student::GetName()
{
return this->name;
}
inline int Student::GetAccept()
{
return this->accept_problem;
}
inline int Student::GetGrade()
{
return this->grade;
}
void Student::Calculate()
{
int i, grade;
this->accept_problem = 0;
this->grade = 0;
for(i = 0; i < this->people; i++)
{
grade = this->questions[i].GetGrade();
if( grade )
{
this->grade += grade;
this->accept_problem += 1;
}
}
}
void Student::SetPeople()
{
cin>>Student::people;
}
bool compare(Student &a,Student &b);
bool compare(Student &a,Student &b)
{
if( a.GetAccept() < b.GetAccept() )
{
return false;
}
if( a.GetAccept() > b.GetAccept() )
{
return true;
}
if( a.GetGrade() < b.GetGrade() )
{
return true;
}
if( a.GetGrade() > b.GetGrade() )
{
return false;
}
if( a.GetName().compare( b.GetName() ) < 0 )
{
return true;
}
else
{
return false;
}
}
void Student::print()
{
cout<<setw(10)<<left<<this->GetName()<<" "<<right<<setw(2)<<this->GetAccept()<<" "<<right<<setw(4)\
<<this->GetGrade()<<endl;
}
int Problem::punish = 0;
int Student::people = 0;
int main()
{
Student *p;
vector<Student>students;
Student::SetPeople();
Problem::SetPunish();
while( cin.peek()!=EOF )
{
p = new Student();
if (!p->GetName().empty())//加
students.push_back(*p);
//删 cin.get();
}
sort(students.begin(),students.end(),compare);
int i = students.size(),j;
for(j = 0; j < i; j++)
{
students[j].print();
}
return 0;
}
#include<iostream>
#include <stdio.h>
#include<cstring>
#include <algorithm>
#include <vector>
using namespace std;
struct student
{
char name[10];
int sum;
int temp;
};
bool com(student a, student b)
{
if(a.sum > b.sum) return true;
if(a.sum < b.sum) return false;
if(a.temp < b.temp) return true;
if(a.temp > b.temp) return false;
if(a.name>b.name) return true;
else return false;
}
int main()
{
int n,m;
cin>>n>>m;
char b[10];
vector<student> a;
int solved;
student p;
while(cin>>p.name)
{
p.sum=0;
p.temp=0;
for(int i=0;i<n;i++)
{
cin>>solved;
if(solved>0)
{
p.temp+=solved;
p.sum++;
}
if(cin.get()=='(')
{
int x;
cin>>x;
p.temp+=x*m;
cin.get();
}
}
a.push_back(p);
}
sort(a.begin(),a.end(),com);
for(int i=0;i<a.size();++i)
printf("%-10s %2d %4d\n",a[i].name,a[i].sum,a[i].temp);
}
#include <iostream>
#include <iomanip>
#include<algorithm>
#include <string>
#include <vector>
using namespace std;
class Problem
{
public:
Problem();
int GetGrade();
static void SetPunish();
private:
int accept_time;
int wrong_times;
static int punish;
};
Problem::Problem()
{
int temp;
cin>>temp;
if(temp<0)
{
this->wrong_times = -temp;
this->accept_time = 0;
}
else
{
if(temp==0)
{
this->wrong_times = 0;
this->accept_time = 0;
}
else
{
this->accept_time = temp;
if( cin.get()=='(')
{
cin>>this->wrong_times;
cin.get();
}
else
{
cin.unget();
this->wrong_times = 0;
}
}
}
}
int Problem::GetGrade()
{
if( this->accept_time==0 )
{
return 0;
}
else
{
return this->accept_time + this->wrong_times * this->punish;
}
}
void Problem::SetPunish()
{
cin>>Problem::punish;
}
class Student
{
public:
Student(string name);
void Calculate();
int GetGrade();
int GetAccept();
string& GetName();
void print();
static void SetPeople();
private:
string name;
Problem *questions;
int accept_problem;
int grade;
static int people;
};
Student::Student(string name)
{
this->name = name;
this->questions = new Problem[this->people];
this->Calculate();
}
inline string& Student::GetName()
{
return this->name;
}
inline int Student::GetAccept()
{
return this->accept_problem;
}
inline int Student::GetGrade()
{
return this->grade;
}
void Student::Calculate()
{
int i, grade;
this->accept_problem = 0;
this->grade = 0;
for(i = 0; i < this->people; i++)
{
grade = this->questions[i].GetGrade();
if( grade )
{
this->grade += grade;
this->accept_problem += 1;
}
}
}
void Student::SetPeople()
{
cin>>Student::people;
}
bool compare(Student &a,Student &b);
bool compare(Student &a,Student &b)
{
if( a.GetAccept() < b.GetAccept() )
{
return false;
}
if( a.GetAccept() > b.GetAccept() )
{
return true;
}
if( a.GetGrade() < b.GetGrade() )
{
return true;
}
if( a.GetGrade() > b.GetGrade() )
{
return false;
}
if( a.GetName().compare( b.GetName() ) < 0 )
{
return true;
}
else
{
return false;
}
}
void Student::print()
{
cout<<setw(10)<<left<<this->GetName()<<" "<<right<<setw(2)<<this->GetAccept()<<" "<<right<<setw(4)\
<<this->GetGrade()<<endl;
}
int Problem::punish = 0;
int Student::people = 0;
int main()
{
Student *p;
string name;
vector<Student>students;
Student::SetPeople();
Problem::SetPunish();
while( cin>>name )//让输入流自己去搞定吧,我不管他了
{
p = new Student(name);
students.push_back(*p);
}
sort(students.begin(),students.end(),compare);
int i = students.size(),j;
for(j = 0; j < i; j++)
{
students[j].print();
}
return 0;
}