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. [ Nowcoder Contest 175 #B ] 区间

    \(\\\) \(Description\) 给出一个长度为\(N\)的序列\(A[1]...A[N]\),定义一个合法区间 \([L,R]\) 当且仅当区间\(GCD\) 在这个区间内,求最长合法区 ...

  2. 常见Z纯CSS小样式合集(三角形)

    三角形 .sanjiao{ width:0px; height: 0px; overflow: hidden; border-width: 100px; border-color: transpare ...

  3. mongo 3.4分片集群系列之八:分片管理

    这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...

  4. 关于使用Axis2 webservice 处理Fault响应时抛org.apache.axis2.AxisFault的分析

    使用Axis2这个框架进行webservice协议通讯,期间出了个问题,我(CLIENT)请求后,当服务端返回符合协议的SOAP异常报文,例如<soap:fault> ... 我的程序直接 ...

  5. C/C++ struct定义、声明、对齐方式

    一.定义/声明方式 第一种:仅有结构体名,不定义/声明变量 struct MyStruct {  int i:     char a[10];     double b; }:第二种:有结构体名,并声 ...

  6. Java二分法查找

    二分法查找 /** * 二分法查找 找不到返回-1 * @author yangzi * */ public class TwoFind { public static int twoFind(int ...

  7. Nginx 通过 certbot 为网站自动配置 SSL 证书并续期

    一.背景知识 1.1.http 和 https 是什么? 简单来说,http 是一个传输网页内容的协议,比如你看到的 http 开头的网站 http://www.163.com ,其网页上的文字.图片 ...

  8. CAD设置背景图片

    把图片作为背景图片可见但是不能编辑操作. 主要用到函数说明: _DMxDrawX::DrawImageToBackground 绘光栅图到背景.详细说明如下: 参数 说明 BSTR sFileName ...

  9. Java编辑编译及运行环境

    Java编辑编译及运行环境 Microsoft Windows 编辑工具 EditPlus JDK JDK(Java Development Kit,Java开发工具包)安装JDK之后,其中bin文件 ...

  10. angularJs 解析factory、service、provider

    了解angular js factory可以认为是设计模式中的工厂方法,就是你提供一个方法,该方法返回一个对象的实例:对于angularJs的factory,就是先定义一个对象,给这个对象添加属性和方 ...