题解 | 小红的密码修改

小红的密码修改

https://www.nowcoder.com/practice/209d146b415c482abf9dc5a91914f00e

#include <iostream>
#include <unordered_map>
using namespace std;

const int num_all= 66;
const int num_first= 26;
const int num_second= 26;
const int num_third= 10;
const int num_firth= 4;


int get_class(char c){
    if(c>='a'&&c<='z') return 1;
    else if(c>='A'&&c<='Z') return 2;
    else if(c>='0'&&c<='9') return 3;
    else return 4;
}

int get_num(int type,unordered_map<int, int>& map){
    switch (type) {
        case 1: return map.at(1)>1 ? num_all-1:num_first-1; break;
        case 2: return map.at(2)>1 ? num_all-1:num_second-1; break;
        case 3: return map.at(3)>1 ? num_all-1:num_third-1; break;
        case 4: return map.at(4)>1 ? num_all-1:num_firth-1; break;
    }
    return 0;
}

int main() {
    int n;
    string s;
    cin>>n;
    unordered_map<int, int> map;
    long long ans=0;
    while(n--){
        ans = 0;
        map[1]=0;
        map[2]=0;
        map[3]=0;
        map[4]=0;
        cin>>s;
        for(char i : s){
            int now_class = get_class(i);
            map[now_class] = map.at(now_class)+1;
        }
        for(char i : s){
            ans += get_num(get_class(i), map);        
        }
        printf("%lld\n",ans);
    }
    
}
// 64 位输出请用 printf("%lld")

没什么好说的,暴力。好久没写cpp了,拿来练习一下

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务