zoukankan      html  css  js  c++  java
  • 算法初步——哈希表B1043输出PATest

    #include <bits/stdc++.h>
    #include<math.h>
    #include <string>
    using namespace std;
    const int MAX_LEN = 10005;
    char str[MAX_LEN];
    int hashTable[30] = {0};
    int main(){
        cin>>str;
        int len = strlen(str);
        int count = 0;
        //map<char,int> result;
        for(int i =0;i<len;++i){
            if(str[i] == 'P' || str[i] == 'A' || str[i] == 'T' || str[i] == 'e' || str[i] == 's' || str[i] == 't'){
                count++;
            }
        }
        map<char,int> result;
        //vector<char> result[count];
        for(int i =0;i<len;++i){
            if(str[i] == 'P' || str[i] == 'A' || str[i] == 'T' || str[i] == 'e' || str[i] == 's' || str[i] == 't'){
                result[str[i]]++;
            }
        }
        map<char,int>::iterator iter;
        /*while(count != 0){
            
        }*/
        /*for(iter = result.begin();iter != result.end();iter++){
            if(iter->)
        }*/
        for(int i =0;i<count;++i){
            //map<char,int>::iterator iter;
            iter = result.begin();
            for(;iter != result.end();++iter){
                if(iter->first == 'P' && iter->second > 0){
                    cout<<iter->first;
                    iter->second--;
                    break;
                }
            }
            iter = result.begin();
            for(;iter != result.end();++iter){
                if(iter->first == 'A' && iter->second > 0){
                    cout<<iter->first;
                    iter->second--;
                    break;
                }
            }
            iter = result.begin();
            for(;iter != result.end();++iter){
                if(iter->first == 'T' && iter->second > 0){
                    cout<<iter->first;
                    iter->second--;
                    break;
                }
            }
            iter = result.begin();
            for(;iter != result.end();++iter){
                if(iter->first == 'e' && iter->second > 0){
                    cout<<iter->first;
                    iter->second--;
                    break;
                }
            }
            iter = result.begin();
            for(;iter != result.end();++iter){
                if(iter->first == 's' && iter->second > 0){
                    cout<<iter->first;
                    iter->second--;
                    break;
                }
            }
            iter = result.begin();
            for(;iter != result.end();++iter){
                if(iter->first == 't' && iter->second > 0){
                    cout<<iter->first;
                    iter->second--;
                    break;
                }
            }
    
        }
        system("pause");
        return 0;
    }
  • 相关阅读:
    NLPIR的语义分析系统
    [译] 12步轻松搞定python装饰器
    python实现爬取千万淘宝商品的方法_python_脚本之家
    Deep Learning(深度学习)学习笔记整理系列 | @Get社区
    那些年,曾经被我们误读的大数据
    值得关注的10个python语言博客
    淘宝的评论归纳是如何做到的?
    pycharm激活码
    Windows下配置Qt 5.8+opencv 3.1.0开发环境
    Ubuntu安装opencv3.1.0后配置环境变量
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12161128.html
Copyright © 2011-2022 走看看