统计 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;
}
相关推荐
NAGNIP1 小时前
一文搞懂树模型与集成模型
算法·面试
NAGNIP1 小时前
万字长文!一文搞懂监督学习中的分类模型!
算法·面试
技术狂人1681 小时前
工业大模型工程化部署实战!4 卡 L40S 高可用集群(动态资源调度 + 监控告警 + 国产化适配)
人工智能·算法·面试·职场和发展·vllm
D_FW1 小时前
数据结构第六章:图
数据结构·算法
a程序小傲2 小时前
京东Java面试被问:动态规划的状态压缩和优化技巧
java·开发语言·mysql·算法·adb·postgresql·深度优先
自学不成才2 小时前
深度复盘:一次flutter应用基于内存取证的黑盒加密破解实录并完善算法推理助手
c++·python·算法·数据挖掘
June`3 小时前
全排列与子集算法精解
算法·leetcode·深度优先
徐先生 @_@|||3 小时前
Palantir Foundry 五层架构模型详解
开发语言·python·深度学习·算法·机器学习·架构
夏鹏今天学习了吗4 小时前
【LeetCode热题100(78/100)】爬楼梯
算法·leetcode·职场和发展