【JZOJ】交换

D e s c r i p t i o n Description Description

给定两个字符串
交换两个字符串的两个字符
是否存在两个字符串都有连续的三个字符
求有多少种交换方式

I n p u t Input Input

两行,每行一个字符串
保证由“G”、“B”、“R”构成

O u t p u t Output Output

一行,为方案总数

S a m p l e I n p u t Sample Input SampleInput
RGBRBR
BRBGRG
S a m p l e O u t p u t Sample Output SampleOutput
1

思路

暴力模拟

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int Ans,len1,len2;
string s1,s2;
bool check1(int x,int y)
{
	if(s2[y]==s1[x-1] && s1[x-1]==s1[x-2])return 1;
	else if(s2[y]==s1[x-1] && s1[x-1]==s1[x+1])return 1;
	else if(s2[y]==s1[x+1] && s1[x+1]==s1[x+2])return 1;
	return 0;
}
bool check2(int x,int y)
{
	if(s1[x]==s2[y-1] && s2[y-1]==s2[y-2])return 1;
	else if(s1[x]==s2[y-1] && s2[y-1]==s2[y+1])return 1;
	else if(s1[x]==s2[y+1] && s2[y+1]==s2[y+2])return 1;
	return 0;
}
int main()
{
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	getline(cin,s1);
	getline(cin,s2);
	len1=s1.length();s1="  "+s1+"  ";
	len2=s2.length();s2="  "+s2+"  ";//防止出界
	for(int i=2;i<=len1+1;++i)
		for(int j=1;j<=len2;++j)//枚举两个点
			if(check1(i,j) && check2(i,j))Ans++;
	printf("%d",Ans);
	fclose(stdin);
	fclose(stdout);
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值