统计 boy girl 复制出来多少次。
cpp
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
void fun(char* s) {
int boy = 0, girl = 0;
int t = 0;
while (*s) {
if (t == 0 && *s!='.') {
t = 1;
if (*s == 'b' || *s == 'o' || *s == 'y')
boy += 1;
else
girl += 1;
}
else if(t==1 && *s!='.') {
if (*s == 'b')
boy += 1;
else if (*s == 'o' && *(s - 1) != 'b')
boy += 1;
else if (*s == 'y' && *(s - 1) != 'o')
boy += 1;
else if (*s == 'g')
girl += 1;
else if (*s == 'i' && *(s - 1) != 'g')
girl += 1;
else if (*s == 'r' && *(s - 1) != 'i')
girl += 1;
else if (*s == 'l' && *(s - 1) != 'r')
girl += 1;
}
s++;
}
printf("%d %d",boy,girl);
}
int main() {
char s[1024] = "......boyogirlyy........girl.......";
fun(s);
return 0;
}