题解 | #名字的漂亮度#
名字的漂亮度
http://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#include<iostream>
using namespace std;
int main() {
int a;
while (cin >> a) {
string b[10];
for (int i = 0; i < a; i++) {
cin >> b[i];
}
for (int i = 0; i < a; i++) {
string c = b[i];
int d = c.length();
int g = 0;
int e[26] = {0};
for (int j = 0; j < d; j++) {
for (int m = 0; m < 26; m++) {
if (c[j] - 'a' == m) {
e[m]++;
}
}
}
for (int k = 0; k < 26 - 1; k++) {
for (int n = k + 1; n < 26; n++) {
if (e[k] < e[n]) {
int f = e[k];
e[k] = e[n];
e[n] = f;
}
}
}
for (int k = 0; k < 26; k++) {
g = g + e[k] * (26 - k);
}
cout << g << endl;
}
}
return (0);
}
using namespace std;
int main() {
int a;
while (cin >> a) {
string b[10];
for (int i = 0; i < a; i++) {
cin >> b[i];
}
for (int i = 0; i < a; i++) {
string c = b[i];
int d = c.length();
int g = 0;
int e[26] = {0};
for (int j = 0; j < d; j++) {
for (int m = 0; m < 26; m++) {
if (c[j] - 'a' == m) {
e[m]++;
}
}
}
for (int k = 0; k < 26 - 1; k++) {
for (int n = k + 1; n < 26; n++) {
if (e[k] < e[n]) {
int f = e[k];
e[k] = e[n];
e[n] = f;
}
}
}
for (int k = 0; k < 26; k++) {
g = g + e[k] * (26 - k);
}
cout << g << endl;
}
}
return (0);
}