POJ1035&&POJ3080&&POJ1936
字符串处理专题,很早就写好了然而忘记写blog了
1035
题意:给你一些单词作为字典。然后让你查找一些单词。对于每个单词,如果在字典中就输出它。否则输出所有它通过删除||增加||替换一个字符能得到的单词
由于数据范围很小,所以我们直接暴力跑一下即可
CODE
#include<string>
#include<iostream>
#include<map>
using namespace std;
const int N=10005;
map <string,bool> hash;
string s[N],t;
int n,m;
inline void swap(string &a,string &b)
{
string temp=a; a=b; b=temp;
}
inline bool cmp(string a,string b)
{
int len_a=a.size(),len_b=b.size();
if (len_a<len_b) swap(a,b),len_a=a.size(),len_b=b.size();
if (len_a-len_b>1) return 0;
if (len_a^len_b)
{
for (register int i=0;i<len_a;++i)
{
string temp=a;
temp.erase(i,1);
if (temp==b) return 1;
}
return 0;
} else
{
int tot=0;
for (register int i=0;i<len_a;++i)
{
if (tot>1) return 0;
if (a[i]^b[i]) ++tot;
}
return tot<=1;
}
}
int main()
{
register int i;
std::ios::sync_with_stdio(false);
//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
while (cin>>s[++n],s[n]!="#")
hash[s[n]]=1; --n;
while (cin>>t,t!="#")
{
if (hash[t]) cout<<t<<" is correct"<<endl; else
{
cout<<t<<":";
for (i=1;i<=n;++i)
if (cmp(s[i],t)) cout<<" "<<s[i];
cout<<endl;
}
}
return 0;
}
3080
题意是给你一些字符串,让你找它们的最长公共字串
同样因为范围很小,所以只需要枚举+find即可
CODE
#include<iostream>
#include<string>
using namespace std;
string s[15],ans;
int n,m,len,tot;
int main()
{
register int i,j,k;
ios::sync_with_stdio(false);
cin>>n;
while(n--)
{
cin>>m; tot=0; ans="";
for (i=1;i<=m;++i)
cin>>s[i]; len=s[1].size();
for (i=0;i<len;++i)
for (j=len-1;j>=i+tot-1;--j)
{
string temp(s[1],i,j-i+1);
bool flag=1;
for (k=2;k<=m;++k)
if (s[k].find(temp)==string::npos) { flag=0; break; }
if (flag)
{
if (temp.size()>tot) tot=temp.size(),ans=temp; else
if (temp.size()==tot&&temp<=ans) ans=temp;
}
}
if (ans.size()<3) cout<<"no significant commonalities"<<endl; else cout<<ans<<endl;
}
return 0;
}
1936
题意:对于两个字符串,判断s1是否为s2的一个子序列
注意这里是子序列,所以不能上find,手动模拟一个一个查找即可
CODE
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s1[100005],s2[100005];
int len1,len2,p;
int main()
{
register int i;
while (scanf("%s%s",&s1,&s2)!=EOF)
{
len1=strlen(s1); len2=strlen(s2); p=0;
bool flag=1;
for (i=0;i<len1;++i)
{
while (s2[p]!=s1[i]&&p<len2) ++p; ++p;
if (p>len2) { flag=0; break; }
}
puts(flag?"Yes":"No");
}
return 0;
}
POJ1035&&POJ3080&&POJ1936的更多相关文章
- poj分类 很好很有层次感。
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 【转】POJ题目分类推荐 (很好很有层次感)
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...
- 【转】ACM训练计划
[转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- acm常见算法及例题
转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题 初期:一.基本算法: (1)枚举. (poj17 ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 转载 ACM训练计划
leetcode代码 利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode. ...
- ACM算法总结及刷题参考
参考:http://bbs.byr.cn/#!article/ACM_ICPC/11777 OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,p ...
随机推荐
- ionic 上拉菜单(ActionSheet)安装和iOS样式不一样
ISO中的界面是这样的: 然而,Android中的界面是这样的: 代码如下: HTML部分: <body ng-app="starter" ng-controller=&qu ...
- mssql 监控随笔
性能监控列表: • Memory: Pages/sec ( 从硬盘上读取或写入硬盘的页数(参考值:00~20) • Physical Disk: % Disk time 或 Physi ...
- 高通 display 驱动【转】
高通display驱动 0. 关键字 MDSS : 高通平台lcd multimedia Display sub system DSI: Display Serial Interface qcom,m ...
- tar压缩/解压用法
格式:tar zcvf 压缩后的路径及包名 你要压缩的文件 z:gzip压缩 c:创建压缩包 v:显示打包压缩解压过程 f:接着压缩 t:查看压缩包内容 x:解压 X:指定文件列表形式排除不需要打包压 ...
- 【redis】redis的雪崩和穿透
1.什么是缓存穿透 一般的缓存系统,都是按照key值去缓存查询,如果不存在对应的value,就应该去DB中查找 .这个时候,如果请求的并发量很大,就会对后端的DB系统造成很大的压力.这就叫做缓存穿透. ...
- 第 13 章 文件输入/输出 (标准I/O)
/*-------------------------- count.c -- 使用标准 I/O --------------------------*/ #include <stdio.h&g ...
- vc获取当前进程CPU使用率
double GetCPUUserRate() { HANDLE hProcess=::GetCurrentProcess(); static DWORD s_dwTickCountOld = 0; ...
- [luogu P4230]连环病原体
[luogu P4230] 连环病原体 题意 给定一个长度为 \(n\) 的边序列, 当这个序列的一个子区间内的边都加入图中时产生了环则称其为"加强区间", 求序列中的每条边在多少 ...
- SpringBoot部署
Spring Boot 部署到服务器 jar 形式 1.打包 若我们在新建Spring Boot 项目的时候,选择打包方式是 jar,则我们只需要用 mvn package 就可以进行打包. 2.运行 ...
- mnist手写数字检测
# -*- coding: utf-8 -*- """ Created on Tue Apr 23 06:16:04 2019 @author: 92958 " ...