题解 | #名字的漂亮度#
名字的漂亮度
http://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
- 大小写转换的位运算
#include<bits/stdc++.h> using namespace std; int main() { int n; while( ~scanf("%d",&n) ) { string str; while( n-- ) { cin>>str; int alphaHash[26]={0}; for( auto c : str ) { if( isupper(c) ) { alphaHash[ (c^' ')-'a' ]++; } else { alphaHash[c-'a']++; } } vector<int> solve; for( int i=0; i<26; ++i) { if( 0!=alphaHash[i] ) { solve.push_back( alphaHash[i] ); } } sort( solve.begin(), solve.end() ); reverse( solve.begin(), solve.end() ); long long sum=0; int loop=26; for(int i=0; i<solve.size(); ++i) { sum+=( loop*solve[i] ); --loop; } cout<<sum<<endl; } } return 0; }