统计 boy girl 复制出来多少次。 浴谷 P1321题

统计 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;
}
相关推荐
剑挑星河月12 分钟前
763.划分字母区间
数据结构·算法·leetcode
programhelp_32 分钟前
Snowflake OA 2026 面经|3道高频真题拆解 + 速通攻略
经验分享·算法·面试·职场和发展
Duang34 分钟前
AI 真能自己写出整个 Windows 系统吗?我做了一场无监督实验
算法·设计模式·架构
少许极端37 分钟前
算法奇妙屋(四十五)-CCPC备战之旅-1
java·开发语言·算法
无小道38 分钟前
算法——找规律
算法·规律
地平线开发者1 小时前
目标检测的 Anchor-Free 和 NMS 到底是什么?
算法·自动驾驶
北顾笙9802 小时前
day24-数据结构力扣
数据结构·算法·leetcode
智者知已应修善业2 小时前
【51单片机独立按键控制往复流水灯启停】2023-6-13
c++·经验分享·笔记·算法·51单片机
pen-ai2 小时前
MAD(Median Absolute Deviation)详解:最稳健的尺度估计方法
人工智能·算法
無限進步D2 小时前
Java 基础算法训练
java·开发语言·算法·入门