AI题库 · 信息学奥赛-提高级题库
题目分享 #22624
#include <iostream>
#include <string>
using namespace std;
const int SIZE = 100;
int main() {
string dict[SIZE];
int rank[SIZE];
int ind[SIZE];
int i, j, n, tmp;
cin >> n;
for (i = 1; i <= n; i++) {
rank[i] = i;
ind[i] = i;
cin >> dict[i];
}
for (i = 1; i < n; i++)
for (j = 1; j <= n - i; j++)
if (dict[ind[j]] > dict[ind[j + 1]]){
tmp = ind[j];
ind[j] = ind[j + 1];
ind[j + 1] = tmp;
}
for (i = 1; i <= n; i++)
rank[ind[i]] = i;
for (i = 1; i <= n; i++)
cout << rank[i] << " ";
cout << endl;
return 0;
}输入:
7
aaa
aba
bbb
aaa
aaa
ccc
aa
输出:_________
AI题库 · 编程考级与信奥赛真题库
查看答案 →
复制链接后可在微信、QQ、小红书等平台粘贴分享;答案与解析在题目页。