题意:任何一个连续四个字符,那四个字符都出现一次,求!分别是几个那四个字符
思路:每一段四个字符所在相对位置必须相同,比如abcdabcd,如果abcdbacd的话 肯定会有一个区间有重复,这里就是bcdb两个b重复了,所以相对位置必须相同,即每个字符%4都相同,模仿q巨写法
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
char s[105];
int main()
{
scanf("%s",s);
int n=strlen(s),res[4]={0},tot[4]={0},cnt[4]={0};
for(int i=0;i<n;i++)
{
tot[i%4]++;
if(s[i]=='R')res[0]=i%4,cnt[0]++;
if(s[i]=='B')res[1]=i%4,cnt[1]++;
if(s[i]=='Y')res[2]=i%4,cnt[2]++;
if(s[i]=='G')res[3]=i%4,cnt[3]++;
}
for(int i=0;i<4;i++)
printf("%d ",tot[res[i]]-cnt[i]);
return 0;
}