C. From S To T

本文介绍了一个字符串操作问题,探讨如何通过移动特定字符使两个字符串相等。提供了详细的算法思路及实现代码,包括检查一个字符串是否为另一个字符串的子串,以及如何使用额外的字符集来补全目标字符串。

 

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given three strings ss, tt and pp consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.

During each operation you choose any character from pp, erase it from pp and insert it into string ss (you may insert this character anywhere you want: in the beginning of ss, in the end or between any two consecutive characters).

For example, if pp is aba, and ss is de, then the following outcomes are possible (the character we erase from pp and insert into ss is highlighted):

  • aba →→ ba, de →→ ade;
  • aba →→ ba, de →→ dae;
  • aba →→ ba, de →→ dea;
  • aba →→ aa, de →→ bde;
  • aba →→ aa, de →→ dbe;
  • aba →→ aa, de →→ deb;
  • aba →→ ab, de →→ ade;
  • aba →→ ab, de →→ dae;
  • aba →→ ab, de →→ dea;

Your goal is to perform several (maybe zero) operations so that ss becomes equal to tt. Please determine whether it is possible.

Note that you have to answer qq independent queries.

Input

The first line contains one integer qq (1≤q≤1001≤q≤100) — the number of queries. Each query is represented by three consecutive lines.

The first line of each query contains the string ss (1≤|s|≤1001≤|s|≤100) consisting of lowercase Latin letters.

The second line of each query contains the string tt (1≤|t|≤1001≤|t|≤100) consisting of lowercase Latin letters.

The third line of each query contains the string pp (1≤|p|≤1001≤|p|≤100) consisting of lowercase Latin letters.

Output

For each query print YES if it is possible to make ss equal to tt, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example

input

Copy

4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa

output

Copy

YES
YES
NO
NO

Note

In the first test case there is the following sequence of operation:

  1. s=s= ab, t=t= acxb, p=p= cax;
  2. s=s= acb, t=t= acxb, p=p= ax;
  3. s=s= acxb, t=t= acxb, p=p= a.

In the second test case there is the following sequence of operation:

  1. s=s= a, t=t= aaaa, p=p= aaabbcc;
  2. s=s= aa, t=t= aaaa, p=p= aabbcc;
  3. s=s= aaa, t=t= aaaa, p=p= abbcc;
  4. s=s= aaaa, t=t= aaaa, p=p= bbcc.

 

 

 

题意:三个字符串s t p,能否将p中的字符放入s中,使其成为t

思路:进行两次判断,1.s是t的字串,2.p中的字符可以补全s,使其成为t

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<set>
#include<map>
#pragma warning(disable:4996)
using namespace std;
const int maxn = 10005;
string s, t, p;
map<char, int>q;
bool check(string s, string t) {//判断s是否是t的子串
	int j = 0;
	for (int i = 0; i < t.length(); i++) {
		for (j; j < s.length(); j++) {
			if (t[i] == s[j]) {
				j++;
				break;
			}
			else {
				break;
			}
		}
	}
	if (j == s.length()) {
		return 1;
	}
	else {
		return 0;
	}
}
int main() {
	int t1;
	scanf("%d", &t1);
	while (t1--) {
		cin >> s >> t >> p;
		bool flag = false;
		if (check(s, t)) {
			q.clear();
			for (int i = 0; i < t.length(); i++) {
				q[t[i]]++;
			}
			for (int i = 0; i < s.length(); i++) {
				q[s[i]]--;
			}
			for (int i = 0; i < p.length(); i++) {
				if (q[p[i]] > 0) {
					q[p[i]]--;
				}
			}
			for (int i = 0; i < t.length(); i++) {
				if (q[t[i]] > 0) {
					flag = true;
					break;
				}
			}
		}
		else {
			flag = true;
		}
		if (flag == true) {
			printf("NO\n");
		}
		else {
			printf("YES\n");
		}
	}
}

 

<think>我们面对的问题:SQL语句中引用了表T_c_dy_duty10080,该表与其他表不在同一个数据库用户(模式)下。 解决方案:需要为T_c_dy_duty10080表添加模式名前缀(即用户名),并确保当前用户有访问该表的权限。如果没有权限,则需要让DBA授权。 步骤: 1. 确定T_c_dy_duty10080表所在的模式(用户)名。假设我们已知该表在模式A下(例如,用户名为SCHEMA_A)。 2. 修改SQL语句,将T_c_dy_duty10080表引用改为SCHEMA_A.T_c_dy_duty10080。 3. 确保当前执行SQL的用户有权限访问SCHEMA_A.T_c_dy_duty10080表。如果没有权限,需要授权(GRANT SELECT ON SCHEMA_A.T_c_dy_duty10080 TO 当前用户;)。 但是,从引用[2]中我们注意到,不同用户访问同一对象可能需要权限。因此,权限问题也需要考虑。 修改后的SQL语句(只修改了T_c_dy_duty10080表的引用): 注意:假设T_c_dy_duty10080表在模式SCHEMA_A下。 原SQL语句片段: ... from t_pbh_problemprocesshis t ... ) a, T_c_dy_duty10080 b, T_WF_CITYCODE c ... 改为: ... from t_pbh_problemprocesshis t ... ) a, SCHEMA_A.T_c_dy_duty10080 b, T_WF_CITYCODE c ... 同时,我们注意到原SQL中还有另一个表T_WF_CITYCODE,如果它也不在当前用户下,也需要同样的处理。但根据问题描述,目前只有T_c_dy_duty10080表不在同一个用户下,所以先处理这个表。 完整修改后的SQL(注意:我们只是将T_c_dy_duty10080改为SCHEMA_A.T_c_dy_duty10080,其他不变): ```sql select t.in_date archiveDate,t.cityname,t.proName duty,count(num) dayCount, row_number() over(partition by t.in_date,t.cityname order by count(num) desc) ranks from ( select a.in_date,c.cityname,max(b.duty) proName,count(1) num from ( select t.privatedynachar101,t.serialno,t.srtypeid,t.subscomplaincity,to_char(t.archivedate,'yyyyMMdd') in_date from t_pbh_problemprocess t where t.acceptmode in ('38','44','45','46','47','50','0102050S','0102050R','0102050T') and t.srtypeid like '000000%' and t.archivedate between to_date(#{startDate}, 'yyyymmddhh24miss') and to_date(#{endDate}, 'yyyymmddhh24miss') union all select t.privatedynachar101,t.serialno,t.srtypeid,t.subscomplaincity,to_char(t.archivedate,'yyyyMMdd') in_date from t_pbh_problemprocesshis t where t.acceptmode in ('38','44','45','46','47','50','0102050S','0102050R','0102050T') and t.srtypeid like '000000%' and t.archivedate between to_date(#{startDate}, 'yyyymmddhh24miss') and to_date(#{endDate}, 'yyyymmddhh24miss') ) a, SCHEMA_A.T_c_dy_duty10080 b, -- 这里添加了模式名前缀 T_WF_CITYCODE c where b.srtypeid = a.srtypeid and c.cityid = a.SUBSCOMPLAINCITY and a.SUBSCOMPLAINCITY in ('01', '02', '03', '04', '05', '06', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17') group by b.duty, c.cityname, a.in_date ) t where t.proName is not null group by t.in_date, t.cityname, t.proName ``` 另外,关于权限问题: 如果当前用户没有访问SCHEMA_A.T_c_dy_duty10080表的权限,执行上述SQL会报错(ORA-01031: insufficient privileges)。因此,需要让DBA或该表的拥有者授予当前用户对该表的SELECT权限。 授权语句示例(由SCHEMA_A用户执行或由DBA执行): ```sql GRANT SELECT ON SCHEMA_A.T_c_dy_duty10080 TO 当前用户; ``` 注意:将“当前用户”替换为实际执行查询的用户名。 如果不知道T_c_dy_duty10080表属于哪个模式,可以通过以下SQL查询(需要有访问数据字典的权限): ```sql SELECT owner, table_name FROM all_tables WHERE table_name = 'T_C_DY_DUTY10080'; -- 注意:表名在数据字典中默认是大写的 ``` 如果查询不到,可能是因为表名在数据库中存储为小写(但通常是大写),或者该表不在当前用户有权限访问的模式中。这时需要确认表名和模式名。 总结: 1. 确定表T_c_dy_duty10080的所属模式。 2. 在SQL中对该表加上模式名前缀。 3. 确保当前用户有该表的SELECT权限。 注意:在修改SQL时,需要确保其他表(如t_pbh_problemprocess, t_pbh_problemprocesshis, T_WF_CITYCODE)在当前用户模式下或者也加了正确的模式名前缀(如果它们也在其他模式下)。根据问题描述,目前只有T_c_dy_duty10080表需要处理。 如果还有其他表不在当前用户下,同样需要添加模式名前缀并授权。 另外,原SQL中使用了绑定变量(#{startDate}, #{endDate}),这可能是MyBatis等框架的写法,无需改动。 </think>根据您的问题,需要将涉及跨用户访问的表 `T_c_dy_duty10080` 拆分处理。以下是详细解决方案和优化建议: ### 解决方案 #### 1. 显式指定表所属模式(Schema) 在 SQL 语句中为跨用户表添加**模式名前缀**(Schema Prefix),确保正确访问: ```sql -- 修改前 ... T_c_dy_duty10080 b ... -- 修改后(假设该表在模式 DY_SCHEMA 下) ... DY_SCHEMA.T_c_dy_duty10080 b ... ``` #### 2. 授权访问权限 若当前用户无权访问目标表,需执行授权操作(需 DBA 或表所有者执行): ```sql GRANT SELECT ON DY_SCHEMA.T_c_dy_duty10080 TO CURRENT_USER; -- CURRENT_USER 替换为实际执行查询的用户 ``` *授权后需重新连接会话生效 [^2]。* #### 3. 完整修改后的 SQL 语句 ```sql SELECT t.in_date archiveDate, t.cityname, t.proName duty, COUNT(num) dayCount, ROW_NUMBER() OVER(PARTITION BY t.in_date, t.cityname ORDER BY COUNT(num) DESC) ranks FROM ( SELECT a.in_date, c.cityname, MAX(b.duty) proName, COUNT(1) num FROM ( SELECT t.privatedynachar101, t.serialno, t.srtypeid, t.subscomplaincity, TO_CHAR(t.archivedate, 'yyyyMMdd') in_date FROM t_pbh_problemprocess t WHERE t.acceptmode IN ('38','44','45','46','47','50','0102050S','0102050R','0102050T') AND t.srtypeid LIKE '000000%' AND t.archivedate BETWEEN TO_DATE(#{startDate}, 'yyyymmddhh24miss') AND TO_DATE(#{endDate}, 'yyyymmddhh24miss') UNION ALL SELECT t.privatedynachar101, t.serialno, t.srtypeid, t.subscomplaincity, TO_CHAR(t.archivedate, 'yyyyMMdd') in_date FROM t_pbh_problemprocesshis t WHERE t.acceptmode IN ('38','44','45','46','47','50','0102050S','0102050R','0102050T') AND t.srtypeid LIKE '000000%' AND t.archivedate BETWEEN TO_DATE(#{startDate}, 'yyyymmddhh24miss') AND TO_DATE(#{endDate}, 'yyyymmddhh24miss') ) a JOIN DY_SCHEMA.T_c_dy_duty10080 b ON b.srtypeid = a.srtypeid -- 关键修改 JOIN T_WF_CITYCODE c ON c.cityid = a.SUBSCOMPLAINCITY WHERE a.SUBSCOMPLAINCITY IN ('01','02','03','04','05','06','08','09','10','11','12','13','14','15','16','17') GROUP BY b.duty, c.cityname, a.in_date ) t WHERE t.proName IS NOT NULL GROUP BY t.in_date, t.cityname, t.proName ``` ### 关键优化说明 1. **显式 JOIN 语法** 将隐式连接(逗号分隔)改为显式 `JOIN...ON` 结构,提高可读性和执行效率。 2. **模式前缀必要性** 跨用户访问必须通过 `schema.table` 格式引用对象,否则会报 `ORA-00942`(表或视图不存在)错误[^2]。 3. **权限验证方法** 检查当前用户权限: ```sql SELECT * FROM all_tables WHERE owner = 'DY_SCHEMA' AND table_name = 'T_C_DY_DUTY10080'; -- 若无返回结果说明无访问权限 ``` ### 相关问题 1. **如何在不切换用户的情况下访问另一个模式下的表?** *答:通过模式名前缀(`schema.table`)访问,并确保已授予 `SELECT` 权限 [^2]。* 2. **授权后仍无法访问表可能的原因是什么?** *答:检查 (1) 授权后会话是否重新连接 (2) 表名大小写敏感(Oracle 默认大写)(3) 同义词冲突 [^2]。* 3. **如何批量修改 SQL 中所有跨用户表的引用?** *答:使用正则表达式替换:查找 `(FROM|JOIN)\s+(\w+\.)?T_c_dy_duty10080\b` 替换为 `$1 DY_SCHEMA.T_c_dy_duty10080`* 4. **多用户环境下如何避免频繁写模式名前缀?** *答:创建同义词简化访问* ```sql CREATE SYNONYM T_c_dy_duty10080 FOR DY_SCHEMA.T_c_dy_duty10080; ``` [^1]: 跨用户数据访问需显式指定模式名 [^2]: 权限不足会导致 ORA-01031 错误,需 GRANT 授权
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值