map, string 强大的STL
Only one case.
a
ahat
hat
hatword
hziee
word
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;
}
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的更多相关文章
- POJ 3096 Surprising Strings(STL map string set vector)
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...
- 入门:Java Map<String,String>遍历及修改
重点:在使用Map时注意key-value,key用于检索value的内容. 在正常情况下,可以不允许重复:在java中分为2中情况,一是内存地址重复,另一个是不同的地址但内容相等. 在使用Map是一 ...
- 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历
分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...
- 使用 JDBC 和 JavaTemplate 查询SQL语句返回 List<Map<String,Object>>
使用JDBC执行sql语句返回List 类型: public class JdbcUtil { private static Log log = LogFactory.getLog(JdbcUtil. ...
- JSONObject,JSONArray,Map,String之间转换
http://blog.csdn.net/superit401/article/details/51727739 1.String转JSONObject String jsonMessage = &q ...
- alibaba fastjson List<Map<String, String>>2Str
import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map; impo ...
- getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:
直接遍历报错:[Ljava.lang.String;@44739f3f Map<String, String> tempMap = new HashMap<String, Strin ...
- List<Map<String,Object>>使用Java代码遍历
List<Map<String,Object>>的结果集怎么使用Java代码遍历以获取String,Object的值: package excel; import java.u ...
- java中对List<Map<String,Object>>中的中文汉字排序
import java.text.Collator;import java.util.ArrayList;import java.util.Collections;import java.util.C ...
随机推荐
- 动态调用链接库(dll) 续
20141118 最近一周做了一个关于仓库管理,拣货任务分配的模块,其中涉及到刷卡自动打印领取任务的功能点. 技术点: C#调用C++.delphi的动态链接库.动态链接库的调用方法不同.效果也不相同 ...
- pycharm永久激活(转载)
转载自CSDN--http://blog.csdn.net/mr_hhh/article/details/79062747 2018-02-2417:30:52 今天再补充一个教程,关于pycharm ...
- Linux学习日记之crontab使用notify-send实现每小时通知提醒
crontab命令用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行 通过crontab -e 可以打开编辑文件添加新的命令 notif ...
- 【译】x86程序员手册25-7.1任务状态段
7.1 Task State Segment 任务状态段 All the information the processor needs in order to manage a task is st ...
- daxcie
Database->Edit Current DBMS菜单 修改如下:选中General选项卡,依次打开Script->Sql->Fomat->CaseSensitivityU ...
- Bootstrap Datatable 简单的基本配置
$(document).ready(function() { $('#example').dataTable({ "sScrollX": "100%", ...
- Vue.js 是什么
Vue.js 是什么 Vue.js(读音 /vjuː/, 类似于 view) 是一套构建用户界面的 渐进式框架.Vue 采用自底向上增量开发的设计. Vue 的核心库只关注视图层. 单页应用:Vue ...
- 官方安装docker-ce步骤
这里是Centos7安装方式 安装依赖包 $ sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 添加Docker ...
- valgrind检查代码内存泄漏,5种内存泄漏情况
摘要: valgrind是linux下用于调试程序和查找内存泄露的常用工具.valgrind会报告5种内存泄露,"definitely lost", "indirectl ...
- 基于APE物理引擎的管线容积率计算方法
容积率一般应用在房地产开发中,是指用地范围内地上总建筑面积与项目总用地面积的比值,这个参数是衡量建设用地使用强度的一项非常重要的指标.在其他行业,容积率的计算也非常重要,如产品利用率.管道使用率等等. ...