#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int rankpts[25] = {0, 25, 20, 18, 15, 12, 11, 10, 9, 8, 7, 6, 5,
4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0};
struct Marble {
string color, name;
vector<int> ranks;
vector<int> pps;
vector<int> fls;
int th, p1, p2, p3, tp, pp, fl, pts;
void calc() {
p1 = p2 = p3 = tp = pp = fl = pts = 0;
int len = ranks.size();
for (int i = 0; i < len; i++) {
if (ranks[i] == 1) {
p1++;
tp++;
} else if (ranks[i] == 2) {
p2++;
tp++;
} else if (ranks[i] == 3) {
p3++;
tp++;
}
pts += rankpts[ranks[i]];
}
len = pps.size();
for (int i = 0; i < len; i++) {
if (pps[i] == 3) {
pp++;
}
pts += pps[i];
}
len = fls.size();
for (int i = 0; i < len; i++) {
if (fls[i] == 2) {
fl++;
}
pts += fls[i];
}
}
bool operator<(Marble &other) {
if (pts != other.pts) {
return pts < other.pts;
}
sort(ranks.begin(), ranks.end(), less<int>());
sort(other.ranks.begin(), other.ranks.end(), less<int>());
int len = ranks.size();
for (int i = 0; i < len; i++) {
if (ranks[i] != other.ranks[i]) {
return ranks[i] > other.ranks[i];
}
}
return false;
}
bool operator>(Marble &other) { return !operator<(other); }
};
vector<Marble> marbles;
int n, m;
bool cmp(Marble a, Marble b) { return a > b; }
void init(ifstream &fin, ofstream &fout) {
fin >> n >> m;
for (int i = 0; i < n; i++) {
Marble marble;
fin >> marble.th >> marble.name >> marble.color;
for (int j = 0; j < m; j++) {
int ptq, rkr, fl;
fin >> ptq >> rkr >> fl;
marble.pps.push_back(ptq);
marble.ranks.push_back(rkr);
marble.fls.push_back(fl);
}
marble.calc();
marbles.push_back(marble);
}
sort(marbles.begin(), marbles.end(), cmp);
for (int i = 0; i < n; i++) {
cout << "Writing... " << i << endl;
Marble marble = marbles[i];
fout << "<tr>";
fout << "<td>" << (i + 1) << "</td>";
int th = i + 1;
if (th < marble.th) {
fout << "<td style=\"color:lime;\">"
<< "<span class=\"fa ";
if (th + 5 <= marble.th) {
fout << "fa-angle-double-up\"></span>";
} else {
fout << "fa-angle-up\"></span>";
}
} else if (th > marble.th) {
fout << "<td style=\"color:red;\">"
<< "<span class=\"fa ";
if (th - 5 >= marble.th) {
fout << "fa-angle-double-down\"></span>";
} else {
fout << "fa-angle-down\"></span>";
}
} else {
fout << "<td>"
<< "<span class=\"fa fa-minus></span>";
}
fout << abs(th - marble.th) << "</td>";
fout << "<td>" << marble.name << "</td>";
fout << "<td style=\"width:50px;background:" << marble.color
<< "\"></td>";
fout << "<td>" << marble.p1 << "</td>";
fout << "<td>" << marble.p2 << "</td>";
fout << "<td>" << marble.p3 << "</td>";
fout << "<td>" << marble.tp << "</td>";
fout << "<td style=\"color:lime;\">" << marble.pp << "</td>";
fout << "<td style=\"color:purple;\">" << marble.fl << "</td>";
fout << "<td>" << marble.pts << "</td>";
fout << "</tr>";
}
}
int main() {
ifstream fin("input.data");
ofstream fout("output.html");
ifstream front("front.html"), back("back.html");
char c;
while (!front.eof()) {
front.get(c);
if (!front.eof())
fout << c;
}
init(fin, fout);
while (!back.eof()) {
back.get(c);
if (!back.eof())
fout << c;
}
return 0;
}
不知道为啥n超过16就不输出Writing了,写出来的文件也不正常……