zoukankan      html  css  js  c++  java
  • POJ2503 UVA10282 Babelfish

    问题链接POJ2503 UVA10282 Babelfish

    问题描述参见上文。

    问题分析这个问题只是一个字典问题,自然用map来实现。问题的关键是时间上能否更快。

    程序说明本来是想用类unordered_map采用哈希搜索的map来编写程序,编译不支持,只好改为map。

    这个问题用类unordered_map来编写程序,时间上会更快一些,也更为合理。

    AC的C++语言程序如下:

    /* POJ2503 UVA1028 Babelfish */
    
    #include <iostream>
    #include <string>
    //#include <unordered_map>
    #include <map>
    #include <sstream>
    
    using namespace std;
    
    int main()
    {
    //    unordered_map<string, string> words;
        map<string, string> words;
        string line, first, second;
        int i;
    
        while (getline(cin, line)) {
            if(line.length() == 0)
                break;
            istringstream sin(line);
            sin >> first >> second;
    
            words[second] = first;
        }
    
        while(getline(cin, line)) {
            i = words.count(line);
            if (i > 0)
                cout << words[line] << endl;
            else
                cout << "eh" << endl;
        }
    
        return 0;
    }


  • 相关阅读:
    缺失的第一个正数
    tuple用法
    整数转罗马数字
    三种时间格式的转换
    不同包的调用
    正则表达式
    lgb模板
    线性回归
    时间序列的特征
    3D聚类
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7564740.html
Copyright © 2011-2022 走看看