统计 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;
}
相关推荐
信奥卷王4 小时前
[GESP202609 六级] 分树规划
算法
夏幻灵4 小时前
LeetCode 21:合并两个有序链表——双指针与哑节点详解
算法·leetcode·链表
徐小黑ACG5 小时前
Golang 基础05 结构体struct
开发语言·算法·golang
Navigator_Z6 小时前
LeetCode //C - 1286. Iterator for Combination
c语言·算法·leetcode
北极有牛6 小时前
cpp学习笔记--常量指针
java·开发语言·算法
GPU实战笔记6 小时前
云端 GPU 训练的账户余额提醒:它能说明什么,不能说明什么?
深度学习·算法·成本管理·gpu云计算·云端训练
浮链序7 小时前
怎么证明"你这个模型是偷我的"——把蒸馏变成取证工具
算法·安全·llm
小O的算法实验室7 小时前
IEEE TMC,面向异构物联网的多目标量子行为拓扑优化算法
算法
liliangcsdn8 小时前
派息率指标的应用探索和分析
大数据·算法