思路:对于“ABABA”可以先枚举“AB”,然后检查下一个串是否等于“AB”,剩下的串就是A,最后检查A和B是否相等;对于“ABABCAB”,同样枚举“AB”,然后匹配剩下两个“AB”,剩下的就是C,注意判断A、B、C三者是否相等。写这题一定要细心,容易写错。

AC代码

#include <cstdio>
#include <cmath>
#include<cctype>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
typedef vector<char> v;
const int maxn = 200 + 5;
char a[maxn];
bool is_same(int st1, int st2, int n) {
	int flag = 1;
	for(int i = st1, j = st2; i < st1+n; ++i, ++j) {
		if(a[i] != a[j]) {
			flag = 0;
			break;
		}
	}
	if(flag) return true;
	return false;
}
int main() {
	int T;
	scanf("%d", &T);
	while(T--) {
		scanf("%s", a);
		int n = 0;
		for(int i = 0; a[i] != '\0'; ++i) {
			if(isalpha(a[i])) {
				a[n++] = a[i];
			}
		}
		int flag = 0;
		//ABABA
		if(n >= 5) for(int i = 2; i <= n/2; ++i) { //枚举AB
			if(i*2 == n || i <= n - 2*i) continue;
			int ok = 1;
			for(int j = i, k = 0; k < i; ++j, ++k) {
				if(a[k] != a[j]) {
					ok = 0;
					break;
				}
			}

			if(ok) {
				for(int j = i*2, k = 0; j < n; ++j, ++k) {
					if(a[j] != a[k]) {
						ok = 0;
						break;
					}
				}
			} 

			if(ok && n-2*i == i - (n-2*i)) {
				ok = !(is_same(0, n-2*i, n-2*i));
			}

			if(ok)  {
				flag = 1;
				break;
			}
		}
		//ABABCAB
		if(!flag && n >= 7) {
			for(int i = 2; i <= n/3; ++i) {
				if(i*3 == n) continue;
				int ok = 1;
				if(!is_same(0, i, i)) ok = 0;
				if(ok) {
					if(!is_same(0, n-i, i)) ok = 0;
				}
				//判断A,B,C是否相等
				int c = n - 3*i;
				if(ok) for(int j = 1; j < i; ++j) { //枚举A的长度
					ok = 0;
					if(j == i-j && is_same(0, j, j)) continue;
					if(c == j && is_same(0, 2*i, j)) continue;
					if(c == i-j && is_same(j, 2*i, c)) continue;
					ok = 1;
					break;
				}
				if(ok) {
					flag = 1;
					break;
				}
			}
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

如有不当之处欢迎指出!

ZOJ - 3818 字符串的更多相关文章

  1. 题目1006:ZOJ问题(字符串处理)

    问题来源 http://ac.jobdu.com/problem.php?pid=1006 问题描述 输入一个只包含'z','o','j'三种字符的字符串,判断是否符合要求. 问题分析 分析AC的三个 ...

  2. D - D ZOJ - 1151 (字符串操作)

    For each list of words, output a line with each word reversed without changing the order of the word ...

  3. ZOJ 3818 Pretty Poem

    暴力模拟 细节处理很重要... #include <iostream> #include <cstring> #include <cstdio> using nam ...

  4. ZOJ 3818 Pretty Poem 模拟题

    这题在比赛的时候WA到写不出来,也有判断ABC子串不一样不过写的很差一直WA 在整理清思路后重写一遍3Y 解题思路如下: 第一种情况:ABABA. 先判断开头的A与结尾的A,得到A的长度, 接着判断A ...

  5. ZOJ 3603字符串操作

    解题思路:找到公共子串然后升序输出 坑的地方就在于输入是存在相同字母的 #include <stdio.h> #include <algorithm> #include < ...

  6. ZOJ 1115 Digital Roots(简单,字符串与数)

    题目 //好一道水水题,可是我居然也错了那么多次,后来百度来发现是因为数据数位可能很长很长,要用字符串数组... //简单 //有坑啊——数据可能很大很大,要用字符串表示! #include<s ...

  7. zoj 1962 How Many Fibs?(字符串化为数字处理)

    事实证明还是,题目拿到手之后,还是还是好好动手划一下比较好,不然直接想打哪!打到哪!很容易乱掉的.将数字倒着弄成字符串比较好处理. #include<stdio.h> #include&l ...

  8. ZOJ 3490 String Successor 字符串处理

    一道模拟题,来模拟进位 暴力的从右往左扫描,按规则求后继就好了.除了Sample已给出的,还有一些需要注意的地方: 9的后继是10,而不是00: (z)的后继是(aa),而不是a(a): 输入虽然最长 ...

  9. ZOJ 3985 - String of CCPC - [字符串处理]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3985 题意: 给出一个长度为n的字符串,全部由'C'和'P'组成 ...

随机推荐

  1. Linux指令--ps

    Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...

  2. linkin大话设计模式--命令模式

    linkin大话设计模式--命令模式 首先考虑一种应用情况,某个方法需要完成某一个功能,这个功能的大部分功能已经确定了,但是有可能少量的步骤没法确定,必须等到执行这个方法才可以确定. 也就是说,我们写 ...

  3. Java多线程之线程其他类

    Java多线程之线程其他类 实际编码中除了前面讲到的常用的类之外,还有几个其他类也有可能用得到,这里来统一整理一下: 1,Callable接口和Future接口 JDK1.5以后提供了上面这2个接口, ...

  4. 腾讯工程师教你玩转 RocksDB

    欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 作者:腾讯云数据库内核团队 原文标题:[腾讯云CDB]教你玩转MyRocks/RocksDB-STATISTICS与后台线程篇 0. Intro ...

  5. Python爬虫进阶(Scrapy框架爬虫)

    准备工作:           配置环境问题什么的我昨天已经写了,那么今天直接安装三个库                        首先第一步:                           ...

  6. java 获取ip地址和网络接口

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  7. php加入环境变量

    一.配置变量 右击计算机-属性-高级系统设置-环境变量-系统变量-双击path,编辑,将php的文件夹路径添加到后面,我是:D:\wamp64\bin\php\php5.6.25 二.测试 当没有加入 ...

  8. Linux下passwd和shadow文件内容详解

    一./etc/passwd /etc/passwd 文件是一个纯文本文件,每行采用了相同的格式: name:password:uid:gid:comment:home:shell name 用户登录名 ...

  9. CSS——盒模型

    1.基本概念: 内容:(content)盒子里面的东西: 填充:(padding)怕盒子里面的东西损坏而添加的泡沫元素活抗震材料: 边框:(border)盒子本身 边界:(margin)则说明盒子的摆 ...

  10. iOS-iOS调用相机调用相册【将图片保存到本地相册】

    设置头部代理 <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 1.调用相机 检测前置摄像头是否可用 - ...