标签:algo cto names tin int printf obj imp actor
数字间以空格分隔。
输出格式:
输出第1行首先给出达到最低分数线的考生人数M,随后M行,每行依照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。
当某类考生中有多人总分同样时,按其德分降序排列;若德分也并列。则按准考证号的升序输出。
输入例子:
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
输出例子:
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; /** * @author jwang1 Success Factors */ public class Main { public static void main(String[] args) { char[] ids = new char[10]; ArrayList<Student> al1 = new ArrayList<Student>(); ArrayList<Student> al2 = new ArrayList<Student>(); ArrayList<Student> al3 = new ArrayList<Student>(); ArrayList<Student> al4 = new ArrayList<Student>(); Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int l = cin.nextInt(); int h = cin.nextInt(); for (int i = 0; i < n; i++) { Student s = new Student(); s.setID(cin.next()); s.setDe(cin.nextInt()); s.setCai(cin.nextInt()); if (s.getDe() >= l && s.getCai() >= l) { if (s.getDe() >= h && s.getCai() >= h) { al1.add(s); } else if (s.getDe() >= h && s.getCai() < h) { al2.add(s); } else if (s.getDe() < h && s.getCai() < h && s.getDe() >= s.getCai()) { al3.add(s); } else { al4.add(s); } } } Collections.sort(al1, new Sort()); Collections.sort(al2, new Sort()); Collections.sort(al3, new Sort()); Collections.sort(al4, new Sort()); System.out.println(al1.size() + al2.size() + al3.size() + al4.size()); for (Student student : al1) { System.out.println(student.getID() + " " + student.getDe() + " " + student.getCai()); } for (Student student : al2) { System.out.println(student.getID() + " " + student.getDe() + " " + student.getCai()); } for (Student student : al3) { System.out.println(student.getID() + " " + student.getDe() + " " + student.getCai()); } for (Student student : al4) { System.out.println(student.getID() + " " + student.getDe() + " " + student.getCai()); } } } class Sort implements Comparator { public int compare(Object o1, Object o2) { Student s1 = (Student) o1; Student s2 = (Student) o2; if ((s1.getCai() + s1.getDe()) != (s2.getCai() + s2.getDe())) { return s2.getCai() + s2.getDe() - s1.getCai() - s1.getDe(); } else if (s1.getDe() != s2.getDe()) { return s2.getDe() - s1.getDe(); } else { return s1.getID().compareTo(s2.getID()); } } } class Student { private String ID; public String getID() { return ID; } public void setID(String iD) { ID = iD; } public int getDe() { return De; } public void setDe(int de) { De = de; } public int getCai() { return Cai; } public void setCai(int cai) { Cai = cai; } private int De; private int Cai; }
//本题仅仅能用C语言的输入输出。用C++的cin和cout会超时 #include <cstdio> #include <algorithm> #include <vector> #include <string> using namespace std; typedef struct Student { string ID; int De; int Cai; }Student; inline bool compare(Student a,Student b) { if ((a.Cai+a.De)!=(b.Cai+b.De)) return a.Cai+a.De>b.Cai+b.De; else if (a.De!=b.De) return a.De>b.De; else return a.ID<b.ID; } inline void print(Student s) { /* cout<<s.ID<<" "<<s.De<<" "<<s.Cai<<endl;*/ printf("%s %d %d\n",s.ID.c_str(),s.De,s.Cai); } int main() { int N,L,H; char id[10]; Student S; string ID; vector<Student> vec1; vector<Student> vec2; vector<Student> vec3; vector<Student> vec4; /* cin>>N>>L>>H;*/ scanf("%d %d %d",&N,&L,&H); while(N--) { /*cin>>S.ID>>S.De>>S.Cai;*/ scanf("%s%d%d",id,&S.De,&S.Cai); S.ID.assign(id); if (S.De>=L&&S.Cai>=L) { if (S.De>=H&&S.Cai>=H) vec1.push_back(S); else if (S.De>=H&&S.Cai<H) vec2.push_back(S); else if (S.De<H&&S.Cai<H&&S.De>=S.Cai) vec3.push_back(S); else vec4.push_back(S); } } sort(vec1.begin(),vec1.end(),compare); sort(vec2.begin(),vec2.end(),compare); sort(vec3.begin(),vec3.end(),compare); sort(vec4.begin(),vec4.end(),compare); /* cout<<vec1.size()+vec2.size()+vec3.size()+vec4.size()<<endl;*/ printf("%d\n",vec1.size()+vec2.size()+vec3.size()+vec4.size()); for_each(vec1.begin(),vec1.end(),print); for_each(vec2.begin(),vec2.end(),print); for_each(vec3.begin(),vec3.end(),print); for_each(vec4.begin(),vec4.end(),print); return 0; }
标签:algo cto names tin int printf obj imp actor
原文地址:http://www.cnblogs.com/cynchanpin/p/7353424.html