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. Spark学习之基础相关组件(1)

    Spark学习之基础相关组件(1) 1. Spark是一个用来实现快速而通用的集群计算的平台. 2. Spark的一个主要特点是能够在内存中进行计算,因而更快. 3. RDD(resilient di ...

  2. AVR单片机8位数码管显示的程序实现

    AVR单片机8位数码管显示的程序实现 转载:http://www.sohu.com/a/117255149_119709   2016-10-26 16:30 我们接着来完成 数码管的显示实验.现在我 ...

  3. Linux系统资源监控--linux命令、nmon和spotlight

    前言: 系统资源监控一般监控系统的CPU,内存,磁盘和网络.系统分为windows和Linux.本篇主要记录Linux. Linux系统资源监控常用命令及工具 一.常用命令:top.free.iost ...

  4. 连接服务器的mysql

    在服务器配置好Mysql 数据库,在客户端连接,报错: 解决方法: 1.在MySQL 数据库中修改user表,将host 中的localhoust 改为 %: 2.配置访问数据库的全选 根据需要配置权 ...

  5. Masonry 原理一

    Under the hood Auto Layout is a powerful and flexible way of organising and laying out your views. H ...

  6. redis的安装和使用【2】redis的java操作

    修改redis.conf# 配置绑定ip,作者机子为192.168.100.192,请读者根据实际情况设置bind 192.168.100.192#非保护模式protected-mode no保存重启 ...

  7. 一起看看 scrollHeight,clientHeight,offsetHeight,scrollTop是个啥

    scrollHeight最终数值的组成: var scrollHeight = currentElementContent.height +currentElement.paddingTop+curr ...

  8. 骑士游历 - dp

    题目地址:http://www.51cpc.com/web/problem.php?id=1586 Summarize: 1. 题目坐标系所给 x,y与惯用表示横纵坐标相反 2. 搜索超时,使用动规: ...

  9. printf函数压栈(i++/i--,++i/--i) 终极解密

    #include <stdio.h> void main() { ; printf("%d %d %d %d\n", i, --i, i, i--); } 输出是“3 ...

  10. Hadoop Mapreduce 中的FileInputFormat类的文件切分算法和host选择算法

    文件切分算法 文件切分算法主要用于确定InputSplit的个数以及每个InputSplit对应的数据段. FileInputFormat以文件为单位切分成InputSplit.对于每个文件,由以下三 ...