题意:给你两个串,第一个串里面的字母都是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的更多相关文章

  1. CodeForces 832B Petya and Exam

    B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. Codefroces 832B Petya and Exam

    B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. E - Petya and Exam CodeForces - 832B 字典树+搜索

    E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...

  4. CodeForces832-B. Petya and Exam

    补的若干年以前的题目,水题,太菜啦_(:з」∠)_    B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...

  5. 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 ...

  6. 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 ...

  7. B. Petya and Exam

    B. Petya and Exam 题目链接 题意 给你一串字符,在这个串中所有出现的字符都是\(good\)字符,未出现的都是\(bad\)字符, 然后给你另一串字符,这个字符串中有两个特殊的字符, ...

  8. 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 ...

  9. CF832B Petya and Exam

    思路: 模拟. 实现: #include <iostream> using namespace std; string a, b; ]; bool solve() { ) return f ...

随机推荐

  1. (replace find)nyoj113-字符串替换

    113-字符串替换 内存限制:64MB 时间限制:3000ms 特判: No通过数:171 提交数:388 难度:2 题目描述: 编写一个程序实现将字符串中的所有"you"替换成& ...

  2. 《Java 程序设计》第一周学习总结

    本周因为刚刚接触Linux和码云等等,所以在完成作业的时候遇到很多问题. 首先,在安装Linux没有安装盘片,在盘片安装之后成功建立虚拟机,建立虚拟机后首先要下载jdk,第一次下载时没有选对格式,Li ...

  3. 110道python面试题

    1.一行代码实现1--100之和 利用sum()函数求和 2.如何在一个函数内部修改全局变量 利用global 修改全局变量 3.列出5个python标准库 os:提供了不少与操作系统相关联的函数 s ...

  4. HTTP常用头部信息

    下面用例子的形式来记录下常用的一些Http头部信息 Request Header: GET /sample.Jsp HTTP/1.1  //请求行 Host: www.uuid.online/  // ...

  5. 20165232 学习基础和c语言基础调查

    做中学读后感 学习是要思考的,仅仅实践是不够的: 不光会动手,还要理解背后的原理 不光会用工具,还要理解支撑的理论 技能是分层次的: 一项技能的掌握程度分为:新手/高级初学者/合格者/精通/专家 对技 ...

  6. Hadoop问题:java.net.SocketException: Network is unreachable

    问题描述:Failed on local exception: java.net.SocketException: Network is unreachable; Host Details : loc ...

  7. ASP.NET Identity V2简单介绍

    Microsoft.AspNet.Identity是微软在MVC 5.0中新引入的一种membership框架,和之前ASP.NET传统的membership以及WebPage所带来的SimpleMe ...

  8. vue实现简单的全选、反选、不选

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 错误记录:vue跟vue编译器版本不一致

    错误如下: error in ./src/Utils.vue Module build failed: Error: Vue packages version mismatch: - vue@ - v ...

  10. [Windows] [VS] [C] [取得指针所指内存的二进制形式字符]

    // 取得指针所指内存的十六进制形式字符串,size指定字节长度#define Mem_toString(address, size) _Mem_toString((PBYTE)address, si ...