统计 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;
}
相关推荐
Aaron158816 分钟前
RFSOC+VU13P/VU9P+GPU通用一体化硬件平台
人工智能·算法·fpga开发·硬件架构·硬件工程·信息与通信·基带工程
c++逐梦人26 分钟前
DFS剪枝与优化
算法·深度优先·剪枝
量化炼金 (CodeAlchemy)28 分钟前
【交易策略】基于随机森林的市场结构预测:机器学习在量化交易中的实战应用
算法·随机森林·机器学习
coder_Eight41 分钟前
LRU 缓存实现详解:双向链表 + 哈希表
前端·算法
重生之我是Java开发战士1 小时前
【动态规划】路径问题:不同路径,珠宝的最高价值,下降路径最小和,最小路径和,地下城游戏
算法·游戏·动态规划
小辉同志1 小时前
739. 每日温度
c++·算法·leetcode
Via_Neo1 小时前
二进制枚举
数据结构·算法·leetcode
荣光属于凯撒1 小时前
P3040 [USACO12JAN] Bale Share S
算法·深度优先
kingcjh971 小时前
十、RL 算法性能调优指南
深度学习·算法
muls11 小时前
java面试宝典
java·linux·服务器·网络·算法·操作系统