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;
    }
  • 相关阅读:
    JSON基本操作
    常用的windowd属性和对象
    手动建立数据库连接的BaseDAO
    注意1:图像插值理论的理解
    Python的Scikit-learn如何选择合适的机器学习算法?
    spark-sklearn(spark扩展scikitlearn)
    Tips-Windows 10【多桌面视窗】操作
    jupyter notebook快捷键速查手册
    使用IntelliJ IDEA进行Python远程调试的需求(未完)
    Bazel构建工具的安装
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12161128.html
Copyright © 2011-2022 走看看