oj1173: LOL

题目要求
Description
HZF非常喜欢游戏LOL。他有一个字符串,他想让其中包含尽量多的字符串“lol”,因此他打算重新排列其中的字母,使连续的“lol”尽量的多。
例如,如果他有字符串“ooll”,他可以得到字符串“lolo”,这样就其中包含了一个“lol”。字符串“lol”出现在字符串的次数为从左向右出现的连续的“lol”的个数。注意(“lolol”这个字符串从左读到右包含两个“lol”)。
因为HZF要打排位赛,没有空余时间,所以他请你写个程序帮他算一下,给定一个字符串最多能得到多少个“lol”。
Input
输入包含多个测试样例。每个测试样例包含一个非空的字符串S(只包含小写字母),S的长度不超过100。
Output
输出满足要求的整数。
Sample Input
Raw
oollx
olooool
loly
lolol
Sample Output
Raw
1
1
1
2
判断条件
即从L开始判断,连续三个字符组成LOL

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
using namespace std;
int main(void)
{
	int i, n, count = 0, count1 = 0, count2 = 0;
	char c[100];
	while (scanf("%s", c) != EOF)
	{
		n = strlen(c);
		for (i = 0; i < n; i++)
		{
			if (c[i] == 'l')
			{
				count1++;
			}
			if (c[i] == 'o')
			{
				count2++;
			}
		}
		if (count1 < 2 || count2 < 1)
		{
			count = 0;
		}
		else if (count1 >= count2 + 1)
		{
			count = count2;
		}

		else
		{
			count = count1 - 1;
		}

		printf("%d\n", count);
		for (i = 0; i < 100; i++)
		{
			c[i] = '\0';
		}
		count = 0; count1 = 0; count2 = 0;
	}
	return 0;
}

发布了12 篇原创文章 · 获赞 2 · 访问量 184

猜你喜欢

转载自blog.csdn.net/qq_45891413/article/details/104610221