第一次没仔细审题:
View Code
1 #include<iostream> 2 #include<sstream> 3 #include<string> 4 #include<vector> 5 using namespace std; 6 7 class stu 8 { 9 public: 10 int sol; 11 string time; 12 int h, m, s;//对应的时分秒 13 int score;//得分 14 bool sm;//标志是否是最小的那个(默认是) 15 stu() 16 { 17 sol = 0; 18 h = 0; 19 m = 0; 20 s = 0; 21 score = 0; 22 time = "0"; 23 sm = true; 24 } 25 friend istream& operator>>(istream& in, stu& x); 26 }; 27 28 inline istream& operator>>(istream& in, stu& x) 29 { 30 in >> x.sol >> x.time; 31 stringstream ss; 32 ss.clear(); 33 ss << x.time; 34 char ch; 35 ss >> x.h >> ch >> x.m >> ch >> x.s; 36 ss.clear(); 37 return in; 38 } 39 40 bool is_small(stu a, stu b) 41 { 42 //解决问题数目相同情况下比较大小 43 if(a.h != b.h) 44 return a.h < b.h; 45 if(a.m != b.m) 46 return a.m < b.m; 47 return a.s < b.s; 48 } 49 50 void f(vector<stu>& svec, int i) 51 { 52 //判断是否是出于前半部分学生 53 int j = i+1; 54 while( j < svec.size()) 55 { 56 if(svec[i].sol == svec[j].sol) 57 { 58 if(!is_small(svec[i], svec[j])) 59 svec[i].sm = false; 60 else 61 svec[j].sm = false; 62 } 63 ++j; 64 } 65 } 66 void mark(stu& a) 67 { 68 //分数等级判断 69 int k = 0; 70 if(a.sm) 71 k = 5; 72 if(a.sol == 5) 73 a.score = 100; 74 else if(a.sol == 4) 75 a.score = 90 + k; 76 else if(a.sol == 3) 77 a.score = 80 + k; 78 else if(a.sol == 2) 79 a.score = 70 + k; 80 else if(a.sol == 1) 81 a.score = 60 + k; 82 else 83 a.score = 50; 84 } 85 void out(vector<stu> svec) 86 { 87 for(int i = 0; i < svec.size(); ++i) 88 { 89 mark(svec[i]); 90 //cout << "slo:" << svec[i].sol << " h:" << svec[i].h << " m:" << svec[i].m << " s:" << svec[i].s <<" score:" << svec[i].score << endl; 91 cout << svec[i].score << endl; 92 } 93 } 94 int main() 95 { 96 int t; 97 while(cin >> t, t >= 0) 98 { 99 vector<stu> svec; 100 stu s; 101 while(t--) 102 { 103 cin >> s; 104 svec.push_back(s); 105 int i = 0; 106 while(i < svec.size()) 107 { 108 f(svec, i); 109 i++; 110 } 111 } 112 out(svec); 113 cout << endl; 114 } 115 return 0; 116 }
后来补充如下:
View Code
1 #include<iostream> 2 #include<sstream> 3 #include<string> 4 #include<cstring> 5 #include<algorithm> 6 #include<vector> 7 using namespace std; 8 9 class stu 10 { 11 public: 12 int sol; 13 string time; 14 int h, m, s;//对应的时分秒 15 int score;//得分 16 bool sm;//标志是否是最小的那个(默认是) 17 stu() 18 { 19 sol = 0; 20 h = 0; 21 m = 0; 22 s = 0; 23 score = 0; 24 time = "0"; 25 sm = false; 26 } 27 friend istream& operator>>(istream& in, stu& x); 28 }; 29 30 inline istream& operator>>(istream& in, stu& x) 31 { 32 in >> x.sol >> x.time; 33 stringstream ss; 34 ss.clear(); 35 ss << x.time; 36 char ch; 37 ss >> x.h >> ch >> x.m >> ch >> x.s; 38 ss.clear(); 39 return in; 40 } 41 42 bool cmp(stu a, stu b) 43 { 44 if(a.sol != b.sol) 45 return a.sol < b.sol; 46 //解决问题数目相同情况下比较大小 47 if(a.h != b.h) 48 return a.h < b.h; 49 if(a.m != b.m) 50 return a.m < b.m; 51 return a.s < b.s; 52 } 53 void mid(vector<string>& a, vector<stu> svec) 54 { 55 //确定中间的那个时间 56 sort(svec.begin(), svec.end(), cmp); 57 int i, k; 58 for(i = 1, k = 0; i < svec.size(); ++i) 59 { 60 if(svec[i].sol != svec[k].sol) 61 { 62 a[svec[k].sol] = svec[(k+i)/2-1].time; 63 //cout << svec[(k+i)/2-1].time << endl; 64 k = i; 65 } 66 } 67 if(i-k > 1) 68 a[svec[k].sol] = svec[(k+i)/2-1].time; 69 else 70 a[svec[k].sol] = svec[k].time; 71 } 72 void f(vector<stu>& svec) 73 { 74 vector<string> a(6, "0"); 75 mid(a, svec); 76 for(int i = 0; i < svec.size(); ++i) 77 if(a[svec[i].sol] >= svec[i].time) 78 svec[i].sm = true; 79 } 80 81 void mark(stu& a) 82 { 83 //分数等级判断 84 int k = 0; 85 if(a.sm) 86 k = 5; 87 if(a.sol == 5) 88 a.score = 100; 89 else if(a.sol == 4) 90 a.score = 90 + k; 91 else if(a.sol == 3) 92 a.score = 80 + k; 93 else if(a.sol == 2) 94 a.score = 70 + k; 95 else if(a.sol == 1) 96 a.score = 60 + k; 97 else 98 a.score = 50; 99 } 100 void out(vector<stu> svec) 101 { 102 for(int i = 0; i < svec.size(); ++i) 103 { 104 mark(svec[i]); 105 cout << svec[i].score << endl; 106 } 107 } 108 int main() 109 { 110 int t; 111 while(cin >> t, t >= 0) 112 { 113 vector<stu> svec; 114 stu s; 115 while(t--) 116 { 117 cin >> s; 118 svec.push_back(s); 119 } 120 f(svec); 121 out(svec); 122 cout << endl; 123 } 124 return 0; 125 } 126 127 128 129 /* 130 5 131 5 06:30:17 132 4 07:31:27 133 4 08:12:12 134 4 05:23:13 135 4 05:24:19 136 137 5 138 1 1:5:6 139 1 1:6:9 140 1 3:5:9 141 1 2:8:32 142 1 4:36:25 143 144 5 145 1 1:5:6 146 1 1:6:9 147 1 3:5:9 148 3 5:6:9 149 3 3:8:32 150 151 4 152 1 1:5:6 153 1 1:6:9 154 1 3:5:9 155 3 5:6:9 156 157 158 */