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. redis之有序集合类型(Zset)——排行榜的实现

    当数据库对排序支持的不是很好,可以利用redis有序集合排序 原文链接:http://blog.csdn.net/loophome/article/details/50373202

  2. [算法天天练] - C语言实现约瑟夫环(2)

    Linux下 #include <stdlib.h>#include <stdio.h> int main(){ int n,m,i,s = 0; printf("E ...

  3. git上手简洁手册

    下载安装git 创建文件夹:learngit 用Git CMD进入文件夹: cd learngit 用Git CMD初始化git: git init 创建文件:新建一个文件在learngit文件夹下, ...

  4. Jmeter在Windows上分布式压测遇到的坑

    1.五星坑:远程启动测试,响应数据为空. controller运行jmeter脚本后,GUI无性能数据返回. agent的jmeter server显示连接后立即结束.看似执行实则响应数据为空. 出现 ...

  5. Deployd的使用

    deployd一个生成后台数据的软件,可以创建json格式的数据,也可以对数据进行增删改查等操作,甚至可以验证登录,简直就是自学好帮手呀,不用后台搞定后台,就用deployd 下载:链接: https ...

  6. Pytorch 加载保存模型【直播】2019 年县域农业大脑AI挑战赛---(三)保存结果

    在模型训练结束,结束后,通常是一个分割模型,输入 1024x1024 输出 4x1024x1024. 一种方法就是将整个图切块,然后每张预测,但是有个不好处就是可能在边界处断续. 由于这种切块再预测很 ...

  7. oracle数据库子查询的结果需要使用多次解决办法

    with c as (select a.trandt,sum(a.tranam) tranam from tran a group by a.trandt )--将子查询抽取出来,以后可以直接用.该方 ...

  8. JAVA基础——IO流字节流

    在Java中把不同的输入输出源(键盘.文件.网路连接)抽象表述为“流”. 1.输入流.输出流 .字节输入流通过FileInputStream和来操作 字节输出流通过FileOutputStream来操 ...

  9. 洛谷——P2171 Hz吐泡泡

    P2171 Hz吐泡泡 题目描述 这天,Hz大大心血来潮,吐了n个不同的泡泡玩(保证没有重复的泡泡).因为他还要写作业,所以他请你帮他把这些泡泡排序成树(左子树<=根<右子树).输出它的后 ...

  10. Python学习-算术运算符,赋值运算符和复合运算符

    算术运算符 常见的算术运算符有 : +     加法运算符 print(1 + 2); // 3 print('1' + '2'); //12 不仅可以进行2个数字的相加,还可以连接2个字符串 -   ...