Educational Codeforces Round 86 (Rated for Div. 2) B.Binary Period

Educational Codeforces Round 86 (Rated for Div. 2) B.Binary Period

题目链接
Let’s say string s has period k if si=si+k for all i from 1 to |s|−k (|s| means length of string s) and k is the minimum positive integer with this property.

Some examples of a period: for s=“0101” the period is k=2, for s=“0000” the period is k=1, for s=“010” the period is k=2, for s=“0011” the period is k=4.

You are given string t consisting only of 0’s and 1’s and you need to find such string s that:

String s consists only of 0’s and 1’s;
The length of s doesn’t exceed 2⋅|t|;
String t is a subsequence of string s;
String s has smallest possible period among all strings that meet conditions 1—3.
Let us recall that t is a subsequence of s if t can be derived from s by deleting zero or more elements (any) without changing the order of the remaining elements. For example, t=“011” is a subsequence of s=“10101”.

Input

The first line contains single integer T (1≤T≤100) — the number of test cases.

Next T lines contain test cases — one per line. Each line contains string t (1≤|t|≤100) consisting only of 0’s and 1’s.

Output

Print one string for each test case — string s you needed to find. If there are multiple solutions print any one of them.

Example

input

4
00
01
111
110

output

00
01
11111
1010

思维题,当字符串只含0或1时直接输出即可,其余的字符串都是 0101 ⋯ 0101\cdots 0101 的子串,所以只要输出 2 ∗ l e n ( s ) 2*len(s) 2len(s) 01 01 01 串即可,AC代码如下:

#include
using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        if(count(s.begin(),s.end(),'0')==0 || count(s.begin(),s.end(),'1')==0) cout<<s;
        else{
            for(int i=0;i<2*s.size();i++)
                cout<<i%2;
        }
        puts("");
    }
    return 0;
}

你可能感兴趣的:(思维,字符串,Codeforces)