problem-A. String Building-codeforces

目录

题目:

输入:

输出:

Examples

input

output

代码:


题目:

You are given a string ss. You have to determine whether it is possible to build the string ss out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any order.

For example:

  • aaaabbb can be built as aa ++ aa ++ bbb;
  • bbaaaaabbb can be built as bb ++ aaa ++ aa ++ bbb;
  • aaaaaa can be built as aa ++ aa ++ aa;
  • abab cannot be built from aa, aaa, bb and/or bbb.

输入:

The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

Each test case consists of one line containing the string ss (1≤|s|≤501≤|s|≤50), consisting of characters a and/or b.

输出:

For each test case, print YES if it is possible to build the string ss. Otherwise, print NO.

You may print each letter in any case (for example, YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

Examples

input

8
aaaabbb
bbaaaaabbb
aaaaaa
abab
a
b
aaaab
bbaaa

output

YES
YES
YES
NO
NO
NO
NO
YES

代码:

#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

const int N = 2e5 + 10;
typedef long long ll;
typedef pair<int, int> PII;
 
int t;
string s;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> t;
	while (t--) {
		cin >> s;
		int f = 1;
		int i = 0;
		int n = s.size();
		int ans = 0;
		while (i < n) {
			int j = i;
			while (s[j] == s[j + 1])
				j++;
			if ((j - i + 1) < 2) {    //如果连续相同的数目小于则2不能
				cout << "NO" << endl;
				f = 0;
				break;
			}
			i = j + 1;
		}
		if (f) {
			cout << "YES" << endl;
		}
	}
 
 
	return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

'<王半仙>'

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值