统计 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;
}
相关推荐
牧杉-惊蛰5 小时前
将数组对象根据自定义排列
java·开发语言·算法
inquisiter6 小时前
损失函数在标量和矩阵上的求导对比
线性代数·算法·矩阵
离凌寒6 小时前
一、关于st上制作外部烧录算法时软件识别不到算法文件的问题总结
算法
青 春 记 忆7 小时前
LeetCode 283. 移动零|Python 解法详解
python·算法·leetcode
Hrain-AI8 小时前
企业 AI 治理运营怎么做:分级授权、Token 用量可观测与模型统一纳管
大数据·人工智能·算法
剑指offer.8 小时前
Linux多任务-线程篇
java·jvm·算法
nike0good8 小时前
CF 126B(Password-z algorithm/exkmp)
开发语言·c++·算法
无定义_9 小时前
Bellman-Ford——贝尔曼福特算法
数据库·算法
HanhahnaH9 小时前
各数据结构操作的时间复杂度汇总
数据结构·算法