C++ 题目描述一年一度的龙舟大赛正在热火朝天地进行。一共有 99 支船队参加比赛每支船队分别位于不同的航道上。观众们通过卫星传输的图像来查看比赛的进度。卫星图可以用 �×�R×S 的字符表示。每一行表示一条航道每条航道至多有一支船队。卫星图的第一列都为 ‘�S’表示起点最后一列都为 ‘�F’表示终点。船队用连续 33个代表其编号的数字表示空白水域用‘’表示。小 �C 想知道现在每支船队的 ���
#include
struct Team { int num; int rank; };
bool compare(const Team& t1, const Team& t2) { return t1.rank < t2.rank; }
int main() {
int R, C;
cin >> R >> C;
vector
vector<Team> teams(9);
for (int i = 0; i < 9; i++) {
teams[i].num = i + 1;
teams[i].rank = 0;
}
for (int c = C-2; c >= 1; c--) {
int rank = 1;
for (int r = 0; r < R; r++) {
if (map[r][c] != '.') {
int teamNum = stoi(map[r].substr(c, 3));
teams[teamNum - 1].rank = rank;
rank++;
}
}
}
sort(teams.begin(), teams.end(), compare);
for (int i = 0; i < 9; i++) {
cout << teams[i].rank << endl;
}
return 0;
原文地址: https://www.cveoy.top/t/topic/iLkG 著作权归作者所有。请勿转载和采集!