• Anagram


    #include <bits/stdc++.h>
    
    using namespace std;
    
    int anagaram(string s){
        // Complete this function
        map<char,int> s1;
        map<char,int> s2;
        int len = s.length();
        if(len%2 != 0 ){
            return -1;
        }
        for(int i = 0; i < len ;i++){
            s1[s[i]]=0;
            s2[s[i]]=0;
        }
        int count=0;
        int half = len / 2;//half = 4(0~7,8个元素)
        for(int i = 0 ;i < half;i++){
            s1[s[i]]++;
            s2[s[i + half]]++;
        }
        map<char,int>::iterator it;
        for(it = s1.begin();it!=s1.end();it++)
        {
            int tmp = it->second-s2[it->first];
            if(tmp>=0)
                count += tmp;
        }
        return count;
    }
    
    int main() {
        int q;
        cin >> q;
        for(int a0 = 0; a0 < q; a0++){
            string s;
            cin >> s;
            int result = anagaram(s);
            cout << result << endl;
        }
        return 0;
    }
     
     
  • 相关阅读:
    如何开发优秀的HTML5游戏?迪斯尼《寻找奥兹之路》游戏技术详解(一)
    C++ Prime学习过程中的细节摘记(三)
    android学习笔记53_采用网页设计软件界面,以及使用android系统内置的浏览器,利用js调用java方法
    黑马韩前成linux从入门到精通の轻松搞定负载均衡
    thinkphp一键清除缓存的方法
    使用treeNMS管理及监控Redis
    ThinkPHP 的缓存大概多久更新一次
    redis查数据
    redis可视化客户端工具TreeNMS
    MeeGo开发进程通信核心 DBus调试工具 狼人:
  • 原文地址:https://www.cnblogs.com/lyf-sunicey/p/8483344.html
Copyright © 2020-2023  润新知