832B Petya and Exam
题意:给你两个串,第一个串里面的字母都是good 字母,
第二个串是模式串,里面除了字母还有?和*(只有一个)
?可以替换所有good字母, *可以替换所有坏字母和空格(可以是多个坏字母!!!这点卡了我很久,也不举一个样例。。。)
然后q次询问,每次给你一个串,问你能否匹配成功,yes or no
思路:暴力,可惜晚上的时候被hacks掉了,真实数据的范围是超过1e5的,比较可惜。
#include <stdio.h>
#include <string.h>
#include <vector>
#include<math.h>
#include <algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define MAXSIZE 1000005
#define LL long long
using namespace std; int vis[MAXSIZE]; int solve(char s1[],char s2[],int index)
{
int len1 = strlen(s1);
int len2 = strlen(s2);
if(len1 > len2 + )
return ;
int id;
if(index == -)
{
if(len1 != len2)
return ;
for(int i=;i<len1;i++)
{
if(s1[i] == '?')
{
id = s2[i] - 'a';
if(!vis[id])
return ;
} else if(s1[i] != s2[i])
return ;
}
return ;
} else
{
int pos1,pos2;
if(len1 - len2 == )
{
pos1 = ;
pos2 = ;
while(pos1<len1 && pos2<len2)
{
if(s1[pos1] == '*')
{
pos1++;
continue;
}
if(s1[pos1] == '?')
{
int id = s2[pos2] - 'a';
if(!vis[id])
return ;
}
else if(s1[pos1] != s2[pos2])
{
return ;
}
pos1++;
pos2++;
}
return ;
}
int s=-,e=-;
for(int i1=,i2=;i1<len1 && i2<len2;i1++,i2++)
{
id = s2[i2] - 'a';
if(!vis[id] && (s1[i1] != s2[i1]))
{
s = i2;
break;
}
} for(int i1=len1-,i2=len2-;i1>= && i2>=;i1--,i2--)
{
id = s2[i2] - 'a';
if(!vis[id] && (s1[i1] != s2[i2]))
{
e = i2;
break;
}
} if(s==- || e==-)
return ; pos1 = ;
pos2 = ;
while(pos1<index && pos2<s)
{
if(s1[pos1] == '?')
{
pos1++;
pos2++;
continue;
} if(s1[pos1] != s2[pos2])
return ;
pos1++;
pos2++;
}
if(pos1 != pos2 || pos1!=s)
return ;
pos1++;
while(pos2<=e)
{
id = s2[pos2] - 'a';
if(vis[id])
return ;
pos2++;
}
while(pos1<len1 && pos2<len2)
{
if(s1[pos1] == '?')
{
pos1++;
pos2++;
continue;
}
else if(s1[pos1] != s2[pos2])
return ;
pos1++;
pos2++;
}
if(pos1!=len1 || pos2!=len2)
return ;
return ;
}
} int main()
{
int n,len,index=-;
char s1[MAXSIZE],s2[MAXSIZE];
cin >> s1;
len = strlen(s1);
for(int i=;i<len;i++)
{
int id = s1[i] - 'a';
vis[id] = ;
}
cin >> s1;
len = strlen(s1);
for(int i=;i<len;i++)
{
if(s1[i] == '*')
{
index = i;
break;
}
}
scanf("%d",&n);
while(n--)
{
cin >> s2;
int ok = solve(s1,s2,index);
if(ok)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
832B Petya and Exam的更多相关文章
- CodeForces 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codefroces 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- E - Petya and Exam CodeForces - 832B 字典树+搜索
E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
- CodeForces832-B. Petya and Exam
补的若干年以前的题目,水题,太菜啦_(:з」∠)_ B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)
题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...
- Codeforces Round #425 (Div. 2) B - Petya and Exam
地址:http://codeforces.com/contest/832/problem/B 题目: B. Petya and Exam time limit per test 2 seconds m ...
- B. Petya and Exam
B. Petya and Exam 题目链接 题意 给你一串字符,在这个串中所有出现的字符都是\(good\)字符,未出现的都是\(bad\)字符, 然后给你另一串字符,这个字符串中有两个特殊的字符, ...
- Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...
- CF832B Petya and Exam
思路: 模拟. 实现: #include <iostream> using namespace std; string a, b; ]; bool solve() { ) return f ...
随机推荐
- getchar(),scanf(),gets(),cin,输入字符串
#include<iostream>#include<stdio.h>#include<string.h>#include<string>using n ...
- 7.Django
1.遍历数据 2.正则表达式匹配数字 ##url超链接 ##配置url ##POST请求需要设置csrf_token
- 如何在Mac上安全彻底的卸载软件?
文章来源:知乎 收录于:风云社区(SCOEE)[提供mac软件下载] 更多专题,可关注小编[磨人的小妖精],查看我的文章,也可上[风云社区 SCOEE],查找和下载相关软件资源. (一)综合类: 新买 ...
- CodeChef - BLACKCOM 可行性dp转最优化树dp
https://www.codechef.com/problems/BLACKCOM 题意:一颗5000个黑白结点的树,10W个查询寻找是否存在大小s并且有t和黑节点的子图 一开始就觉得应当是一个树d ...
- USB_4大描述符
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aaa6695798/archive/2009/11/06/4776202.aspx 在USB描述符中,从上到下分为四个 ...
- spring-data-redis分布式
本文转载http://hbxflihua.iteye.com/blog/2383495 1.引入spring-data-redis依赖的jar 包 <dependency> <gro ...
- Dev-Tips
186 Chrome DevTools: How to use Logpoints for quicker JavaScript debugging You can use the new Logpo ...
- vs code解决golang开发环境问题 dial tcp 216.239.37.1:443: connectex: A connection attempt failed
安装插件是出现 如下错误提示, https fetch failed: Get https://golang.org/x/tools/cmd/gorename?go-get=1: dial tcp 2 ...
- 解决svn检出后不显示图标的问题
解决svn检出后不显示图标的问题: 此文经过个人验证,可以解决TortoiseSVN图标显示异常问题: 问题出现原因:Windows Explorer Shell 支持 Overlay Icon 最多 ...
- 049、准备overlay网络实验环境(2019-03-14 周四)
参考https://www.cnblogs.com/CloudMan6/p/7270551.html 为了支持容器跨主机通信,Docker提供了overlay driver,使用户可以创建基于Vx ...