1703D. Double Strings

D. Double Strings

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given nn strings s1,s2,…,sns1,s2,…,sn of length at most 88.

For each string sisi, determine if there exist two strings sjsj and sksk such that si=sj+sksi=sj+sk. That is, sisi is the concatenation of sjsj and sksk. Note that jj can be equal to kk.

Recall that the concatenation of strings ss and tt is s+t=s1s2…spt1t2…tqs+t=s1s2…spt1t2…tq, where pp and qq are the lengths of strings ss and tt respectively. For example, concatenation of "code" and "forces" is "codeforces".

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1051≤n≤105) — the number of strings.

Then nn lines follow, the ii-th of which contains non-empty string sisi of length at most 88, consisting of lowercase English letters. Among the given nn strings, there may be equal (duplicates).

The sum of nn over all test cases doesn't exceed 105105.

Output

For each test case, output a binary string of length nn. The ii-th bit should be 11 if there exist two strings sjsj and sksk where si=sj+sksi=sj+sk, and 00 otherwise. Note that jj can be equal to kk.

Example

input

Copy

3
5
abab
ab
abc
abacb
c
3
x
xx
xxx
8
codeforc
es
codes
cod
forc
forces
e
code

output

Copy

10100
011
10100101

Note

In the first test case, we have the following:

  • s1=s2+s2s1=s2+s2, since abab=ab+ababab=ab+ab. Remember that jj can be equal to kk.
  • s2s2 is not the concatenation of any two strings in the list.
  • s3=s2+s5s3=s2+s5, since abc=ab+cabc=ab+c.
  • s4s4 is not the concatenation of any two strings in the list.
  • s5s5 is not the concatenation of any two strings in the list.

Since only s1s1 and s3s3 satisfy the conditions, only the first and third bits in the answer should be 11, so the answer is 1010010100.

昨天就是被这道屑题卡住,想的太复杂,不如直接动手做。

题意大概是找到该字符串在整个字符串组中有没有两个字符串加来等于该字符串的,有的话,该位置就是1否则就是0.

思路大概就是把字符串以此分成两份,再到整个字符串组中去找这两个字符串是否存在。

#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
const int manx = 2e6 + 10;
long long a[manx];
long long b[manx];
string s[manx];
int main()
{
	int t;
	cin >> t;

	while (t--)
	{
		int n;
		cin >> n;
		string k;
		set<string>yuuka;//放到set中进行查找工作。
		for (int i = 0; i < n; i++)
		{
			cin >> s[i];
			yuuka.insert(s[i]);
		}
		for (int i = 0; i < n; i++)	
		{	
			int ok = 0;
			for (int j = 1; j < s[i].size(); j++)
			{
			
			string x = s[i].substr(0, j); 
			string y = s[i].substr(j);//把s[i]分成两个字串如aba分为a,ab,下一个循环分为ab,a。
				
			if (yuuka.count(x) && yuuka.count(y))//如果在整个字符串数组中能同时查到x,y就说明存在否则就不存在。
				ok = 1;
			}
			k.push_back('0' + ok);	
		}
		cout << k;
		cout << endl;
	}
}

Q21: Which of the following is a valid user-defined output stream manipulator header? a. ostream& tab( ostream& output ) b. ostream tab( ostream output ) c. istream& tab( istream output ) d. void tab( ostream& output ) Q22: What will be output by the following statement? cout << showpoint << setprecision(4) << 11.0 << endl; a. 11 b. 11.0 c. 11.00 d. 11.000 Q23: Which of the following stream manipulators causes an outputted number’s sign to be left justified, its magnitude to be right justified and the center space to be filled with fill characters? a. left b. right c. internal d. showpos Q24: Which of the following statements restores the default fill character? a. cout.defaultFill(); b. cout.fill(); c. cout.fill( 0 ); d. cout.fill( ' ' ); Q25: When the showbase flag is set: a. The base of a number precedes it in brackets. b. Decimal numbers are not output any differently. c. "oct" or "hex" will be displayed in the output stream. d. Octal numbers can appear in one of two ways. Q26: What will be output by the following statements? double x = .0012345; cout << fixed << x << endl; cout << scientific << x << endl; a. 1.234500e-003 0.001235 b. 1.23450e-003 0.00123450 c. .001235 1.234500e-003 d. 0.00123450 1.23450e-003 Q27: Which of the following outputs does not guarantee that the uppercase flag has been set? a. All hexadecimal numbers appear in the form 0X87. b. All numbers written in scientific notation appear the form 6.45E+010. c. All text outputs appear in the form SAMPLE OUTPUT. d. All hexadecimal numbers appear in the form AF6. Q28: Which of the following is not true about bool values and how they're output with the output stream? a. The old style of representing true/false values used -1 to indicate false and 1 to indicate true. b. A bool value outputs as 0 or 1 by default. c. Stream manipulator boolalpha sets the output stream to display bool values as the strings "true" and "false". d. Both boolalpha and noboolalpha are “sticky” settings.
05-24
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值