admin管理员组文章数量:1558098
How do you remove consecutive spaces in a simple editor like notepad in Microsoft Windows? One way is to repeatedly “replace all” two consecutive spaces with one space (we call it an action). In this problem, you’re to simulate this process and report the number of such “replace all” actions.
For example, if you want to remove consecutive spaces in “A very big joke.”, you need two actions:
‘‘Averybigjoke.’’ -> ‘‘Averybigjoke.’’ -> ‘‘Averybigjoke.’’
Input
The input contains multiple test cases, one in a separate line. Each line contains letters, digits, punctuations and spaces (possibly leading spaces, but no trailing spaces). There will be no TAB character in the input. The size of input does not exceed 1MB.
Output
For each line, print the number of actions that are required to remove all the consecutive spaces.
Explanation
If you can’t see clearly, here is the sample input, after replacing spaces with underscores:
A*very␣␣big␣␣␣␣joke.
␣␣␣␣␣␣␣␣␣Goodbye!
Sample Input
A very big joke.
Goodbye!
Sample Output
2
4
问题链接:UVA12416 Excessive Space Remover
问题简述:(略)
问题分析:
简单题不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA12416 Excessive Space Remover */
#include <bits/stdc++.h>
using namespace std;
int main()
{
int c, spcnt = 0, maxsp = 0;
while((c = getchar()) != EOF) {
if(c == ' ') spcnt++;
else if(c == '\n') {
printf("%d\n", (int)ceil(log2(maxsp)));
spcnt = 0, maxsp = 0;
} else
maxsp = max(maxsp, spcnt), spcnt = 0;
}
return 0;
}
本文标签: 对数字符excessiveRemoverSpace
版权声明:本文标题:UVA12416 Excessive Space Remover【对数+字符流】 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1727308034a1107533.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论