ZOJ - 3818 字符串
思路:对于“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 字符串的更多相关文章
- 题目1006:ZOJ问题(字符串处理)
问题来源 http://ac.jobdu.com/problem.php?pid=1006 问题描述 输入一个只包含'z','o','j'三种字符的字符串,判断是否符合要求. 问题分析 分析AC的三个 ...
- D - D ZOJ - 1151 (字符串操作)
For each list of words, output a line with each word reversed without changing the order of the word ...
- ZOJ 3818 Pretty Poem
暴力模拟 细节处理很重要... #include <iostream> #include <cstring> #include <cstdio> using nam ...
- ZOJ 3818 Pretty Poem 模拟题
这题在比赛的时候WA到写不出来,也有判断ABC子串不一样不过写的很差一直WA 在整理清思路后重写一遍3Y 解题思路如下: 第一种情况:ABABA. 先判断开头的A与结尾的A,得到A的长度, 接着判断A ...
- ZOJ 3603字符串操作
解题思路:找到公共子串然后升序输出 坑的地方就在于输入是存在相同字母的 #include <stdio.h> #include <algorithm> #include < ...
- ZOJ 1115 Digital Roots(简单,字符串与数)
题目 //好一道水水题,可是我居然也错了那么多次,后来百度来发现是因为数据数位可能很长很长,要用字符串数组... //简单 //有坑啊——数据可能很大很大,要用字符串表示! #include<s ...
- zoj 1962 How Many Fibs?(字符串化为数字处理)
事实证明还是,题目拿到手之后,还是还是好好动手划一下比较好,不然直接想打哪!打到哪!很容易乱掉的.将数字倒着弄成字符串比较好处理. #include<stdio.h> #include&l ...
- ZOJ 3490 String Successor 字符串处理
一道模拟题,来模拟进位 暴力的从右往左扫描,按规则求后继就好了.除了Sample已给出的,还有一些需要注意的地方: 9的后继是10,而不是00: (z)的后继是(aa),而不是a(a): 输入虽然最长 ...
- ZOJ 3985 - String of CCPC - [字符串处理]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3985 题意: 给出一个长度为n的字符串,全部由'C'和'P'组成 ...
随机推荐
- junit设计模式--组合模式
Composite,英语翻译下,复合,组合. 组合模式有时候又叫做部分-整体模式,它使我们在树形结构的问题中,模糊了简单元素和复杂元素的概念,客户程序可以像处理简单元素一样来处理复杂元素,从而使得客户 ...
- linux(ubuntu或Deepin等)+win7双系统升级win10出现grub解决办法
1,set root=(hd0,msdos11) 2,set prefix=(hd0,msdos11)/boot/grub 3,insmod /boot/grub/i386-pc/normal.mod ...
- redis数据类型-散列类型
Redis数据类型 散列类型 Redis是采用字典结构以键值对的形式存储数据的,而散列类型(hash)的键值也是一种字典结构,其存储了字段(field)和字段值的映射,但字段值只能是字符串,不支持其他 ...
- linux socket 编程(C语言)[转]
最近看了一些网络编程的书籍,一直以来总感觉网络编程神秘莫测,其实网络编程入门还是很容易学的,下面这些代码是我在linux下编写的,已经运行过了,编译之后就可以运行了.有不足之处希望大家多多指出,共同学 ...
- linux下安装pip
1.pip下载安装 wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d ...
- JMeter监控服务器CPU、内存的方法
jmeter也可以像loadrunner一样监控服务器CPU.内存等性能参数,不过需要安装一些插件 一.首先下载监控服务器的插件 链接:https://pan.baidu.com/s/1o9Zuw ...
- 利用innodb_force_recovery修复MySQL数据页损坏
现象:启动MySQL服务时报1067错误,服务无法启动. 查看xxx.err错误日志发现有数据页损坏信息: InnoDB: Database page corruption on disk or a ...
- C++ 关于字符串总结(持续更新)
1.find_first_of size_type find_first_of( const basic_string &str, size_type index = 0 ); size_ty ...
- R语言dplyr包初探
昨天学了一下R语言dplyr包,处理数据框还是很好用的.记录一下免得我忘记了... 先写一篇入门的,以后有空再写一篇详细的用法. #dplyr learning library(dplyr) #fil ...
- 联合查询到gridview
using com.DAL.Base; using DAL.ruanmou; using System; using System.Collections.Generic; using System. ...