码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1247 Hat’s Words(map,STL,字符处理,string运用)

时间:2014-08-13 12:56:36      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   

题目

 

用map写超便捷

也可以用字典树来写

 

我以前是用map的:

 

bubuko.com,布布扣
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<math.h>
#include <iostream>
#include<map>
using namespace std;
string word[50010];
int main()
{
    int i=0,n,len,j;
    map<string,int>m;
//    map<string,int>::iterator q;
    while(cin>>word[i])
    {
        m[word[i++]]=1;//这里是标记该单词在map里的
    }
    n=i;
    for(i=0;i<n;i++)
    {
        len=word[i].length();
        for(j=0;j<len;j++)
        {
            string s1(word[i],0,j);//C++中string的操作:复制函数:word[i]的 0~j 位复制给s1
            string s2(word[i],j);//同上:复制函数:j~末位(前边必要加string 定义?)
            if(m[s1]==1&&m[s2]==1)
            {
                cout<<word[i]<<endl;
                break;
            }
        }
    }
    return 0;
}
View Code

 

HDU 1247 Hat’s Words(map,STL,字符处理,string运用),布布扣,bubuko.com

HDU 1247 Hat’s Words(map,STL,字符处理,string运用)

标签:style   blog   http   color   os   io   for   ar   

原文地址:http://www.cnblogs.com/laiba2004/p/3909567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!