Title Description
There is an interesting string value calculation: the number of statistics for each string of characters appears, and then squaring the number of all the characters and value as strings
such as: string "abacaba", which includes four 'a', 2 'b', 1 a 'c', then this string value is 4 * 4 + 2 + 1 * 2 * 1 = 21
beef has a string s, s and allows you to be removed from the most k characters, your goal is to make the minimum value of the string get.
such as: string "abacaba", which includes four 'a', 2 'b', 1 a 'c', then this string value is 4 * 4 + 2 + 1 * 2 * 1 = 21
beef has a string s, s and allows you to be removed from the most k characters, your goal is to make the minimum value of the string get.
Enter a description:
Input consists of two lines, the first line of a string s, s is the length of the string length (1 ≤ length ≤ 50) , which contains only lowercase letters ( 'a' - 'z' ). The second row contains an integer k (0 ≤ k ≤ length) , i.e., the number of characters allowed to be removed.
Output Description:
Output An integer representing the minimum value obtained
Example 1
Export
copy2
#include <iostream> #include <string> #include <algorithm> using namespace std; bool cmp(const int &x,const int &y) { return x>y; } int main() { string str; int de_num=0,sum=0; int dele_num,arr_size=0; int arr[300];fill(arr,arr+300,0);// array by excessive time will be difficult getline (CIN, STR); CIN >> dele_num; // COUT << 'A' - '0' << endl; // 49 for ( int I = 0 ; I <STR .size (); I ++ ) ARR [STR [I] - ' 0 ' ] ++; // note is [STR [I] - '0'] Sort (ARR + 49 , ARR + 49 + 26 is , CMP); // The first pass sorted (descending) // Note that this has been wrong before because before i think the Sort (+ 97 arr, arr + 97 + 26, cmp); // for (int i = 49; i <49 + 26 ; i ++) // why ordered from 49 starts because of 'a' ascll 98, '0' is 49, so the 'a' in the first subscript arr element should be 49 // COUT << arr [I ] <<" "; int K = 49 ; the while (dele_num-- ) { ARR [K] - ; Sort (ARR + 49 , ARR + 49 + 26 is , CMP); // continue sort } for ( int I = 49 ; I < 49 + 26 is ; I ++ ) SUM + ARR = [I] * ARR [I]; COUT << SUM; return 0 ; } / * use Case: wersrsresesrsesrawsdsw . 11 corresponding to the output must be: 23 Your output is: 31 * /