zoukankan      html  css  js  c++  java
  • hdu 1247 map的使用

    http://acm.hdu.edu.cn/showproblem.php?pid=1247

    Hat’s Words

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 7760    Accepted Submission(s): 2814


    Problem Description
    A hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
    You are to find all the hat’s words in a dictionary.
     
    Input
    Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 50,000 words.
    Only one case.
     
    Output
    Your output should contain all the hat’s words, one per line, in alphabetical order.
     
    Sample Input
    a
    ahat
    hat
    hatword
    hziee
    word
     
    Sample Output
    ahat
    hatword
     

    ////////////////////////////////////////////////////////////////////////////////////////////////////

    可以用map做,但是用字典树好一点,暂时还不会,留个坑

    #include <stdio.h>
    #include <string.h>
    #include <map>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    int main()
    {
        string str[50010];
        int tmp=0;
        int tot=0;
        map<string,int> cas;
        while(cin>>str[tot++])
        {
             cas[str[tot-1]]=1;
        }
        for(int i=0;i<tot;i++)
        {
            for(int j=1;j<str[i].length();j++)
            {
                  if(cas[str[i].substr(0,j)]==1 && cas[str[i].substr(j)]==1)
                  {
                      cout<<str[i]<<endl;
                      break;
                  }
            }
        }
        return 0;
    }
  • 相关阅读:
    vue+element ui 实现菜单无限极菜单
    DOM事件绑定原理和传播机制
    数组和对象的深浅克隆
    new源码分析和Object.create的重写
    原型和原型链的学习
    4.3 模型参数的延后初始化
    4.2 模型参数的访问、初始化和共享
    CSAPP Float Point
    4.1 模型构造
    3.16 实战Kaggle比赛:房价预测
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3889165.html
Copyright © 2011-2022 走看看