[字符串]TrBBnsformBBtion
TrBBnsformBBtion
Let us consider the following operations on a string consisting of A and B:
- Select a character in a string. If it is
A, replace it withBB. If it isB, replace withAA. - Select a substring that is equal to either
AAAorBBB, and delete it from the string.
For example, if the first operation is performed on ABA and the first character is selected, the string becomes BBBA. If the second operation is performed on BBBAAAA and the fourth through sixth characters are selected, the string becomes BBBA.
These operations can be performed any number of times, in any order.
You are given two string S and T, and q queries ai,bi,ci,di. For each query, determine whether SaiSai+1…Sbi, a substring of S, can be made into TciTci+1…Tdi, a substring of T.
数据范围
- 1≤|S|,|T|≤105
- S and T consist of letters
AandB. - 1≤q≤105
- 1≤ai≤bi≤|S|
- 1≤ci≤di≤|T|
输入
Input is given from Standard Input in the following format:
S
T
q
a1 b1 c1 d1
…
aq bq cq dq
输出
Print q lines. The i-th line should contain the response to the i-th query. If SaiSai+1…Sbi can be made into TciTci+1…Tdi, print YES. Otherwise, print NO.
输入样例1
BBBAAAABA
BBBBA
4
7 9 2 5
7 9 1 4
1 7 2 5
1 7 2 4
输出样例1
YES
NO
YES
NO
The first query asks whether the string ABA can be made into BBBA. As explained in the problem statement, it can be done by the first operation.
The second query asks whether ABA can be made into BBBB, and the fourth query asks whether BBBAAAA can be made into BBB. Neither is possible.
The third query asks whether the string BBBAAAA can be made into BBBA. As explained in the problem statement, it can be done by the second operation.
输入样例2
AAAAABBBBAAABBBBAAAA
BBBBAAABBBBBBAAAAABB
10
2 15 2 13
2 13 6 16
1 13 2 20
4 20 3 20
1 18 9 19
2 14 1 11
3 20 3 15
6 16 1 17
4 18 8 20
7 20 3 14
输出样例2
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO 代码:
# include <bits/stdc++.h>
using namespace std; const int N = ;
char s[N], t[N];
int sp[N], tp[N], q, a, b, c, d;
int main() {
scanf("%s%s%d", s + , t + , &q);
for (int i = ; s[i]; ++i) {
sp[i] = sp[i - ] + s[i] - 'A' + ;
}
for (int i = ; t[i]; ++i) {
tp[i] = tp[i - ] + t[i] - 'A' + ;
}
while(q--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if ( (sp[b] - sp[a - ]) % == (tp[d] - tp[c - ]) % ) {
printf("YES\n");
}
else {
printf("NO\n");
}
}
return ;
}
[字符串]TrBBnsformBBtion的更多相关文章
- Python高手之路【六】python基础之字符串格式化
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- 测试一下StringBuffer和StringBuilder及字面常量拼接三种字符串的效率
之前一篇里写过字符串常用类的三种方式<java中的字符串相关知识整理>,只不过这个只是分析并不知道他们之间会有多大的区别,或者所谓的StringBuffer能提升多少拼接效率呢?为此写个简 ...
- java中的字符串相关知识整理
字符串为什么这么重要 写了多年java的开发应该对String不陌生,但是我却越发觉得它陌生.每学一门编程语言就会与字符串这个关键词打不少交道.看来它真的很重要. 字符串就是一系列的字符组合的串,如果 ...
- JavaScript 字符串实用常操纪要
JavaScript 字符串用于存储和处理文本.因此在编写 JS 代码之时她总如影随形,在你处理用户的输入数据的时候,在读取或设置 DOM 对象的属性时,在操作 Cookie 时,在转换各种不同 Da ...
- Java 字符串格式化详解
Java 字符串格式化详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 文中如有纰漏,欢迎大家留言指出. 在 Java 的 String 类中,可以使用 format() 方法 ...
- Redis的简单动态字符串实现
Redis 没有直接使用 C 语言传统的字符串表示(以空字符结尾的字符数组,以下简称 C 字符串), 而是自己构建了一种名为简单动态字符串(simple dynamic string,sds)的抽象类 ...
- ASP.NET加密和解密数据库连接字符串
大家知道,在应用程序中进行数据库操作需要连接字符串,而如果没有连接字符串,我们就无法在应用程序中完成检索数据,创建数据等一系列的数据库操作.当有人想要获取你程序中的数据库信息,他首先看到的可能会是We ...
- Javascript正则对象方法与字符串正则方法总结
正则对象 var reg = new Regexp('abc','gi') var reg = /abc/ig 正则方法 test方法(测试某个字符串是否匹配) var str = 'abc123'; ...
- 微信小程序中利用时间选择器和js无计算实现定时器(将字符串或秒数转换成倒计时)
转载注明出处 改成了一个单独的js文件,并修改代码增加了通用性,点击这里查看 今天写小程序,有一个需求就是用户选择时间,然后我这边就要开始倒计时. 因为小程序的限制,所以直接选用时间选择器作为选择定时 ...
随机推荐
- Windows下好用的git客户端--GitExtentions
用git: https://git-scm.com/downloads GitExtentions: https://sourceforge.net/projects/gitextensions/ B ...
- debian下arp欺骗
sudo sysctl -w net.ipv4.ip_forward= sudo sysctl -p arpspoof -i eth0 -t 目标ip -r 伪装ip或者ettercap -i eth ...
- SAS LOGISTIC 逻辑回归中加(EVENT='1')和不加(EVENT='1')区别
区别在于:最大似然估计分析中估计是刚好正负对调加上EVENT:%LET DVVAR = Y;%LET LOGIT_IN = S.T3;%LET LOGIT_MODEL = S.Model_Params ...
- Let'sencrypt.sh 抛出异常: Response: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)>
起因 今天网站的SSL证书过期了,打算重新申请,运行 Let'sencrypt.sh 的时候抛出了这么个异常. 一番搜索,发现居然找不到直接的答案.没有直接的答案就只能通过间接的答案来解决了. 希望我 ...
- 二、CSS选择器
1.CSS派生选择器 概念:通过依据元素在其位置的上下文关系来定义样式. 实例: <!--index.html--> <!DOCTYPE html> <html lang ...
- oracle的权限和角色
1 介绍 这一部分我们主要看看oracle是如何管理权限和角色的,权限和角色的区别在哪里. 当刚刚建立用户时,用户没有任何权限,也不能执行任何操作.如果要执行某种特定的数据库操作,则必须为其授予系统 ...
- java并发编程目录
java并发编程目录 Java多线程基础:进程和线程之由来 JAVA多线程实现的四种方式 Java并发编程:线程间协作的两种方式:wait.notify.notifyAll和Condition Jav ...
- leetcode每日刷题计划-简单篇day3
收到swe提前批面试hhh算是ep挂了的后续 努力刷题呀争取今年冲进去! Num 21 合并两个有序链表 Merge Two Sorted Lists 注意新开的链表用来输出结果的是ListNode ...
- CPU与内存互联的架构演变
随着计算机中CPU核数目的增加,传统的UMA(unifonn memory access)架构由于对关键硬件(如中央内存控制器)的竞争加剧出现了性能上的瓶颈,即扩展性不强.而NUMA架构则以其良好的可 ...
- String和StringBuilder、StringBuffer的区别
String对象一旦创建之后该对象是不可更改的,但后两者的对象是变量,是可以更改的. String:适用于少量的字符串操作的情况 StringBuilder:适用于单线程下在字符缓冲区进行大量操作的情 ...