TrBBnsformBBtion

Let us consider the following operations on a string consisting of A and B:

  1. Select a character in a string. If it is A, replace it with BB. If it is B, replace with AA.
  2. Select a substring that is equal to either AAA or BBB, 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+1Sbi, a substring of S, can be made into TciTci+1Tdi, a substring of T.

数据范围

  • 1≤|S|,|T|≤105
  • S and T consist of letters A and B.
  • 1≤q≤105
  • 1≤aibi≤|S|
  • 1≤cidi≤|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+1Sbi can be made into TciTci+1Tdi, 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的更多相关文章

  1. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  2. 测试一下StringBuffer和StringBuilder及字面常量拼接三种字符串的效率

    之前一篇里写过字符串常用类的三种方式<java中的字符串相关知识整理>,只不过这个只是分析并不知道他们之间会有多大的区别,或者所谓的StringBuffer能提升多少拼接效率呢?为此写个简 ...

  3. java中的字符串相关知识整理

    字符串为什么这么重要 写了多年java的开发应该对String不陌生,但是我却越发觉得它陌生.每学一门编程语言就会与字符串这个关键词打不少交道.看来它真的很重要. 字符串就是一系列的字符组合的串,如果 ...

  4. JavaScript 字符串实用常操纪要

    JavaScript 字符串用于存储和处理文本.因此在编写 JS 代码之时她总如影随形,在你处理用户的输入数据的时候,在读取或设置 DOM 对象的属性时,在操作 Cookie 时,在转换各种不同 Da ...

  5. Java 字符串格式化详解

    Java 字符串格式化详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 文中如有纰漏,欢迎大家留言指出. 在 Java 的 String 类中,可以使用 format() 方法 ...

  6. Redis的简单动态字符串实现

    Redis 没有直接使用 C 语言传统的字符串表示(以空字符结尾的字符数组,以下简称 C 字符串), 而是自己构建了一种名为简单动态字符串(simple dynamic string,sds)的抽象类 ...

  7. ASP.NET加密和解密数据库连接字符串

    大家知道,在应用程序中进行数据库操作需要连接字符串,而如果没有连接字符串,我们就无法在应用程序中完成检索数据,创建数据等一系列的数据库操作.当有人想要获取你程序中的数据库信息,他首先看到的可能会是We ...

  8. Javascript正则对象方法与字符串正则方法总结

    正则对象 var reg = new Regexp('abc','gi') var reg = /abc/ig 正则方法 test方法(测试某个字符串是否匹配) var str = 'abc123'; ...

  9. 微信小程序中利用时间选择器和js无计算实现定时器(将字符串或秒数转换成倒计时)

    转载注明出处 改成了一个单独的js文件,并修改代码增加了通用性,点击这里查看 今天写小程序,有一个需求就是用户选择时间,然后我这边就要开始倒计时. 因为小程序的限制,所以直接选用时间选择器作为选择定时 ...

随机推荐

  1. DataSource - 常用数据库连接池 (DBCP、c3p0、Druid) 配置说明

    1. 引言 1.1 定义 数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库 ...

  2. 利用 Chrome 原生功能截图网页全图

    打开你想截图的网页了,然后按下 F12(macOS 是 option + command + i)调出开发者工具,接着按「Ctrl + Shift + P」(macOS 是 command + Shi ...

  3. git tag 常用操作

    1.获取最新tag(获取不到就多获取几次) git fetch origin  或者 git fetch origin <tagname> 2. checkout tag到本地分支(如果看 ...

  4. EasyMock 模拟对象测试

    一.EasyMock 使用动态代理实现模拟对象创建,一般可以满足以下测试需求 1.要测试的模块依赖于其它自己控制不了的模块,如第三方服务,其它组员在开发的服务等,它们都没办法配合你来测试: 2.涉及到 ...

  5. JVM优化系列之一(-Xss调整Stack Space的大小)

    Java程序中,每个线程都有自己的Stack Space(堆栈).这个Stack Space不是来自Heap的分配.所以Stack Space的大小不会受到-Xmx和-Xms的影响,这2个JVM参数仅 ...

  6. 并发之lock的condition接口

    13.死磕Java并发-----J.U.C之Condition 12.Condition使用总结 11.Java并发编程系列之十七:Condition接口 === 13.死磕Java并发-----J. ...

  7. Linux网站运维工程师基础大纲

    第一阶段:Linux运维基础 第一章:Linux基础以及入门介绍 1.Linux硬件基础 2.Linux发展过程 3.创建虚拟机和系统安装 第二章:Linux系统目录结构介绍 1.Linux系统优化 ...

  8. 笔记本 原来win10系统改装win7系统遇到 invaid signature detected.check secure boot policy setup问题

    这次操作的笔记本电脑是   华硕R414U 大家如果遇到类似问题的话也可以参考这个方法,但是必须搞清楚电脑的型号,型号不同操作起来有差别的 我这里选择的重装系统的方法是最简单粗暴的硬盘安装方法,怎么硬 ...

  9. mysql 5.7 配置

    MySQL安装文件分为两种,一种是msi格式的,一种是zip格式的.如果是msi格式的可以直接点击安装. zip格式是自己解压,解压缩之后其实MySQL,配置完就可以使用了. 1,配置环境变量很简单: ...

  10. python_10 迭代器和生成器

    迭代器协议: 1.迭代器协议是指:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么就引起一个Stopiteration异常,以终止迭代(只能往后走不能往前退) 2.可迭代对象:实现 ...