zoj 3818(暴力)

题意:有一个字符串如果能写成ABABA或ABABCAB的形式且A、B、C不相等就输出yes,否则no。

题解:直接暴力。

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <ctype.h>
#include <algorithm>
using namespace std;
const int N = 55;
string str, s;
int l;

bool judge1() {
	l = s.length();
	int len1 = (l - 2) / 3, cnt = 0;
	char a[N], b[N];
	while (1) {
		cnt++;
		if (cnt > len1)
			break;
		if ((l - cnt * 3) % 2 == 0) {
			int cnt2 = (l - cnt * 3) / 2, i, j;
			for (i = 0; i < cnt; i++)
				a[i] = s[i];
			for (i = cnt; i < cnt + cnt2; i++)
				b[i - cnt] = s[i];
			for (i = cnt + cnt2, j = 0; i < 2 * cnt + cnt2; i++, j++)
				if (s[i] != a[j])
					break;
			if (i < 2 * cnt + cnt2)
				continue;
			for (i = cnt * 2 + cnt2, j = 0; i < 2 * cnt + 2 * cnt2; i++, j++)
				if (s[i] != b[j])
					break;
			if (i < 2 * cnt + 2 * cnt2)
				continue;
			for (i = cnt * 2 + cnt2 * 2, j = 0; i < l; i++, j++)
				if (s[i] != a[j])
					break;
			if (i < l)
				continue;
			if (cnt == cnt2) {
				for (int i = 0; i < cnt; i++)
					if (a[i] != b[i])
						return true;
			}
			else
				return true;
		}
	}
	return false;
}

bool judge2() {
	l = s.length();
	int len1, len2, len3;
	if (l < 7)
		return false;
	for (len1 = 1; len1 <= l / 3; len1++)
		for (len2 = 1; len2 <= l - len1 * 3; len2++) {
			len3 = l - len1 * 3 - len2 * 3;
			if (len3 <= 0)
				continue;
			string s1, s2, s3, s4, s5, s6, s7;
			s1 = s.substr(0, len1);
			s2 = s.substr(len1, len2);
			if (s1 == s2)
				continue;
			s3 = s.substr(len1 + len2, len1);
			s4 = s.substr(len1 + len2 + len1, len2);
			s5 = s.substr(len1 * 2 + len2 * 2, len3);
			s6 = s.substr(len1 * 2 + len2 * 2 + len3, len1);
			s7 = s.substr(len1 * 3 + len2 * 2 + len3, len2);
			if (s1 == s3 && s3 == s6 && s2 == s4 && s4 == s7 && s1 != s5 && s2 != s5)
				return true;
		}
	return false;
}

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		cin >> str;
		s = "";
		int len = str.length();
		for (int i = 0; i < len; i++)
			if ((str[i] <= 'z' && str[i] >= 'a') || (str[i] <= 'Z' && str[i] >= 'A'))
				s += str[i];
		if (judge1())
			printf("Yes\n");
		else if (judge2())
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值