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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
# include<cstring>
using namespace std;
#define MAX 51000
map<string,int> m;
string ch[MAX];
int main()
{
char ch1[100],ch2[100];
int i=0; while(cin>>ch[i])
{
m[ch[i++]]=1;
}
for(int j=0;j<i;j++)
{
for(int k=1;k<ch[j].size()-1;k++)
{
string ch1(ch[j],0,k); //表示把ch[j]中从下标0開始连续的k个字符串赋给ch1
string ch2(ch[j],k,ch[j].size()-k);
if(m[ch1]==1&&m[ch2]==1)
{
cout<<ch[j]<<endl;
break;
}
}
}
return 0;
}

 指针做:::;
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string>
# include<cstring>
using namespace std;
#define MAX 51000
string ch[MAX];
struct node{
bool isword;
node *next[26];
node()
{
isword=0;
memset(next,NULL,sizeof(next));
}
}; int insert(node *root,string s)
{
node *p=root;
for(int i=0;i<s.size();i++)
{
int id=s[i]-'a';
if(p->next[id]==NULL) p->next[id]= new node();
p= p->next[id];
}
p->isword=1;
}
int find(node *root,string s)
{
node *p =root;
for(int i=0;i<s.size();i++)
{
int id=s[i]-'a';
if(p->next[id]==NULL) return 0;
p=p->next[id];
}
return p->isword;
}
int main()
{
char ch1[100],ch2[100];
int i=0;
node *root=new node();
while(cin>>ch[i])
{
insert(root,ch[i]);
i++;
}
for(int j=0;j<i;j++)
{
for(int k=1;k<ch[j].size()-1;k++)
{
string ch1(ch[j],0,k); //表示把ch[j]中从下标0開始连续的k个字符串赋给ch1
string ch2(ch[j],k,ch[j].size()-k);
if(find(root,ch1)==1&&find(root,ch2)==1)
{
cout<<ch[j]<<endl;
break;
}
}
}
return 0;
}

Codeforces Round #286 (Div. 2)    A. Mr. Kitayuta's Gift



题意:  给你一个字符串,从字符a到字符z选一个字母插入不论什么位置使之成为回文串,不行输出“NA”。

代码:    讨厌暴力有木有。

。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; bool ispal(string str)
{
string hh=str;
reverse(hh.begin(),hh.end());
return hh==str ? 1:0;
}
int main()
{
string ss;
while(cin>>ss)
{
bool flag=0;
int len=ss.size();
int h,i;
for(i=0; i<=len; i++)
{ for(char j='a'; j<='z'; j++)
{
string xa;
for(h=0; h<i; h++) xa+=ss[h];
xa+=j;
for(h=i; h<len; h++) xa+=ss[h];
if(ispal(xa))
{
cout<<xa<<endl;
flag=1;
break;
}
}
if(flag) break;
}
if(!flag) puts("NA"); }
return 0;
}

Codeforces
Round #300
  Cutting Banne
r

题意:
         在一段不超过100的字符串中减掉一些子串之后能组成"CODEFORCES"则输出YES
技巧:   对string进行取子串操作,S.substr(start,length)

int main()
{
#ifndef ONLINE_JUDGE
freopen("in.cpp","r",stdin);
#endif
string s;
string str1; while(cin>>s)
{
for(int i=0;i<s.size();i++)
{
for(int j=i+1;j<s.size();j++)
{
str1=s.substr(0,i)+s.substr(j);
if(str1=="CODEFORCES")
{
printf("YES\n");
return 0;
}
}
}
puts("NO");
}
return 0;
}*/

 


map, string 强大的STL的更多相关文章

  1. POJ 3096 Surprising Strings(STL map string set vector)

    题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...

  2. 入门:Java Map<String,String>遍历及修改

    重点:在使用Map时注意key-value,key用于检索value的内容. 在正常情况下,可以不允许重复:在java中分为2中情况,一是内存地址重复,另一个是不同的地址但内容相等. 在使用Map是一 ...

  3. 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历

    分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...

  4. 使用 JDBC 和 JavaTemplate 查询SQL语句返回 List<Map<String,Object>>

    使用JDBC执行sql语句返回List 类型: public class JdbcUtil { private static Log log = LogFactory.getLog(JdbcUtil. ...

  5. JSONObject,JSONArray,Map,String之间转换

    http://blog.csdn.net/superit401/article/details/51727739 1.String转JSONObject String jsonMessage = &q ...

  6. alibaba fastjson List<Map<String, String>>2Str

    import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map; impo ...

  7. getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:

    直接遍历报错:[Ljava.lang.String;@44739f3f Map<String, String> tempMap = new HashMap<String, Strin ...

  8. List<Map<String,Object>>使用Java代码遍历

    List<Map<String,Object>>的结果集怎么使用Java代码遍历以获取String,Object的值: package excel; import java.u ...

  9. java中对List<Map<String,Object>>中的中文汉字排序

    import java.text.Collator;import java.util.ArrayList;import java.util.Collections;import java.util.C ...

随机推荐

  1. 对于es6的小小理解之generator函数

    相信很多学js的人都看过es6,我也是最近才看的es6标准.下面我来说一下我对es6笼统的看法,如有不对欢迎评论交流. js有很长很长的历史,大家应该都有了解过.es6是15年发布的版本,由TC39主 ...

  2. Js上传图片并生成缩略图

    Js上传图片并显示缩略图的流程为 Js选择文件->Jquery上传图片->服务器接收图片流->存储图片->返回结果到Js端->显示缩略图 本文上传图片所用的Js库是aja ...

  3. 微信小程序组件解读和分析:五、text文本

    text文本组件说明: text 文本就是微信小程序中显示出来的文本. text文本组件的示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 1 2 3 4 <v ...

  4. 4星|《DK商业百科》:主要商业思想与事件的概括

    全书分为以下6章:1:企业的起步与发展:2:领导和人力资源:3:理财:4:战略和运营:5:营销管理:6:生产与生产后.每章有拆分为成多个比较小的专题,阐述相关专题的主要的商业思想与实践. 基本是作者按 ...

  5. GPC:使用GPC计算intersection容易出现的问题

    在使用GPC计算多边形的交的时候,出现问题 //1.2. 另一种方法,判断新的多边形是否和老多边形相交     Poly cross = (PolyDefault) Clip.intersection ...

  6. Crash reporter

    A crash reporter is a software application whose function is to identify report crash details and to ...

  7. Jmeter的属性和变量

    jmeter的属性和变量可以简单理解为编程里面的全局变量和局部变量.属性是全局可见,可以跨线程组传递调用,而变量基本上只能存在于一个线程组中(在测试计划定义的变量也是可以跨线程组传递的).同线程组内的 ...

  8. VMware 12虚拟机下Ubuntu 16连不上网解决方法

    打开自带Firefox浏览器,显示连接不上网,终端下 ping 也显示 unkown   解决方法: 1.打开虚拟机的“编辑”选项,选择“虚拟网络编辑器” 2.选择VMnet8(我不知道为啥VMnet ...

  9. Flask框架 之request对象

    一.request对象属性 属性 说明 类型 data 记录请求的数据,并转换为字符串 * form 记录请求中的表单数据 MultiDict args 记录请求中的查询参数 MultiDict co ...

  10. PHP封装数据库

    (1)按照步骤封装数据库 ①引入抽象类和抽象方法,即引入模板: ②继承抽象类,注意参数(规定几个就传入几个): ③逐个写入抽象方法,必须一一对应:(抽象方法必须一一引入,否则会报错-->有个抽象 ...