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 ...
随机推荐
- 在Linux中复制文件夹下的全部文件到另外文件夹
https://jingyan.baidu.com/article/656db918f83c0de380249c5a.html 在Linux系统中复制或拷贝文件我们可以用cp或者copy命令,但要对一 ...
- linux之/proc
/proc是Linux或UNIX中的一种伪文件系统机制,提供了访问内核运行结构.改变内核设置的实时数据. 与ext4.NFS.FAT32等文件系统不同,/proc中的数据存放在内存而不是硬盘上. 在/ ...
- qml: 以鼠标为中心进行放缩;
import QtQuick 2.9 import QtQuick.Window 2.2 import QtQuick.Controls 2.2 Window { visible: true widt ...
- JDBC工具类
package com.shundong.uitl; import java.sql.Connection; import java.sql.DriverManager; import java.sq ...
- mybatis多数据源报错
2018-12-06 16:58:35,709 [ main ] - [ INFO ] [ org.springframework.core.KotlinDetector : 57 ] - Kotli ...
- 为什么要两次调用encodeURI来解决乱码问题
.encodeURL函数主要是来对URI来做转码,它默认是采用的UTF-8的编码.. UTF-8编码的格式:一个汉字来三个字节构成,每一个字节会转换成16进制的编码,同时添加上%号. 假设页面端输入的 ...
- C#设计模式(5)——建造者模式
1.建造者模式介绍 在软件开发中,有时我们要创建一个复杂的对象,这个对象由几个子部件按一定的步骤组合而成,这时候我们就可以使用建造者模式了.说到建造者我们首先想到的是盖房子,盖房子简单的说有三个步骤: ...
- Project facet Java version 1.8 not supported
把其它的项目到自己的eclipse中后,进行运行项目之后,就会提示为“Project facet Java version 1.8 not supported”. 进行更改配置,进行右键项目就会弹 ...
- spring-data-redis时效设置
本人转自http://hbxflihua.iteye.com/blog/2320584#bc2396403 spring目前在@Cacheable和@CacheEvict等注解上不支持缓存时效设置,只 ...
- css3实现单行文本溢出显示省略号
文本超出一定宽度让其隐藏,以省略号替代 width:200px; white-space:nowrap; text-overflow:ellipsis; overflow:hidden; 如下图