import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main (String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
String val=line.toLowerCase();
char[]hist=new char[26];
for(int i=0;i<val.length();i++){
if(val.charAt(i)>='a' && val.charAt(i)<='z'){
hist[val.charAt(i)-'a']++;
}
}
Arrays.sort(hist);
int sum=0;
for(int i=hist.length-1;i>-1;i--){
sum+=hist[i]*(i+1);
}
sb.append(sum).append('\n');
}
System.out.print(sb);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main (String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
String val=line.toLowerCase();
char[]hist=new char[26];
for(int i=0;i<val.length();i++){
if(val.charAt(i)>='a' && val.charAt(i)<='z'){
hist[val.charAt(i)-'a']++;
}
}
Arrays.sort(hist);
int sum=0;
for(int i=hist.length-1;i>-1;i--){
sum+=hist[i]*(i+1);
}
sb.append(sum).append('\n');
}
System.out.print(sb);
}
}
No comments:
Post a Comment