简易占座

Problem D: 简易占座

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 198   Solved: 42
[ Submit][ Status][ Web Board]

Description

新学期开始了,小明提早到自习教室帮同学占座,一本书可以占两个相邻座位,小明只想占一整排座位,求总共需要几本书来占满这一排空余座位?

Input

题目有多组测试数据

先输入一个数据n,表示这一排总共有多少个座位,再输入一行座位状态,"*"为不能占座,"@"为可以占座。

Output

输出需要几本书占座,如果没有座位可以来占座,则输出"Oh no!"

Sample Input

1
*
6
@**@@@

Sample Output

Oh no!
3

HINT
#include <iostream>
#include <string>
using namespace std;
int main() 
{ 
	int n,sum=0;
	string str;
	cin>>n>>str;
	for(int i=0;i<n;i++)
	{
		
		if(str[i] == '*')    // if the current char is '*', we just move one step
			continue;
		else                   // if the current char is '@', we move two steps, no matter what the next char is
		{                
			i++;
			sum++;
		}      
	}
	if(sum == 0)             
		cout<<"Oh no!"<<endl;
	else
		
		cout<<sum<<endl;
	
	return 0; 
} 

PS:唉!转载的!!!难过

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值