社区讨论
给每个歌赋权值然后排序,wa#2~#9
P1159排行榜参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mhjrfyh5
- 此快照首次捕获于
- 2025/11/04 07:17 4 个月前
- 此快照最后确认于
- 2025/11/04 07:17 4 个月前
CPP
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
const int N = 105;
using namespace std;
typedef struct line {
int w;
string s;
};
line S[N];
int n;
bool cmp(const line& A, const line& B)
{
return A.w < B.w;
}
int cnt1,vis[N];
int main()
{
cin >> n;
int cnt2 = n-1;
for (int i = 0; i < n; i++)
{
string x, y;
cin >> x >> y;
S[i].s = x;
if (y[0] == 'U')
{
while (vis[cnt2])cnt2--;
vis[cnt2] = 1;
S[i].w = cnt2;
}
else if (y[0] == 'D')
{
while (vis[cnt1])cnt1++;
vis[cnt1] = 1;
S[i].w =cnt1;
}
else
{
S[i].w = i;
vis[S[i].w] = 1;
}
}
sort(S, S + n, cmp);
for (int i = 0; i <n; i++)
cout << S[i].s << endl;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...