Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items?
The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100characters. If the i-th character in the string is the letter "С", that means that the i-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the i-th character is the letter "P", than the i-th object on the wall is a photo.
Print the only number — the minimum number of times Polycarpus has to visit the closet.
CPCPCPC
7
CCCCCCPPPPPP
4
CCCCCCPPCPPPPPPPPPP
6
CCCCCCCCCC
2
In the first sample Polycarpus needs to take one item to the closet 7 times.
In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice.
In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice.
In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go).
以now为参考标准进行统计~
完整代码:
/*30ms,0KB*/
#include<cstdio>
#include<cstring>
#include<cmath>
char str[101];
int main()
{
int count = 0, i = 0;
scanf("%s", str);
int len = strlen(str);
char now = str[0];
while (i < len)
{
int nowcount = 1;
while (++i < len && str[i] == now)
++nowcount;
count += ceil((double)nowcount / 5);
now = str[i];
}
printf("%d", count);
return 0;
}
邮票与照片整理挑战

本文介绍了一个关于如何最高效地将墙上排列的邮票和照片分批移除并存入储物柜的问题。主人公Polycarpus在不同时携带两种物品的前提下,需要计算最少的往返次数以完成任务。

被折叠的 条评论
为什么被折叠?



