CF#581(Div2) A. BowWow and the Timetable

A. BowWow and the Timetable

http://codeforces.com/contest/1204/problem/A

In the city of Saint Petersburg, a day lasts for 21002100 minutes. From the main station of Saint Petersburg, a train departs after 11 minute, 44minutes, 1616 minutes, and so on; in other words, the train departs at time 4k4k for each integer k≥0k≥0. Team BowWow has arrived at the station at the time ss and it is trying to count how many trains have they missed; in other words, the number of trains that have departed strictly before time ss. For example if s=20s=20, then they missed trains which have departed at 11, 44 and 1616. As you are the only one who knows the time, help them!

Note that the number ss will be given you in a binary representation without leading zeroes.

Input

The first line contains a single binary number ss (0≤s<21000≤s<2100) without leading zeroes.

Output

Output a single number — the number of trains which have departed strictly before the time ss.

Examples

input

Copy

100000000

output

Copy

4

Note

In the first example 1000000002=256101000000002=25610, missed trains have departed at 11, 44, 1616 and 6464.

In the second example 1012=5101012=510, trains have departed at 11 and 44.

The third example is explained in the statements.

也不知何时能变绿,昨天一看到第一道题,woc,签到题简单啊,但是菜逼最后这道题并没有成功签到。

错误解法:进制转换,输入的二进制数转换为十进制数,然后for语句循环,每次变化范围i*=4,cnt++,其实吧,我举得逻辑没有问题,我过不去的原因是大数,当输入的字符串(二进制数)特别长时,就过不去。

题解:看了题解发现自己思路错了按照自己的做法需要写出大数二进制转换为十进制。题解给的方法直接是数学方法,应该算是简单的逻辑和基础数学的结合。

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=2001;
char str[maxn];
int main()
{
  int cnt=0,ans=0;
  cin>>(str+1);
  int len=strlen(str+1);
  for(int i=1;i<=len;i++)
  {
    if(str[i]=='1')
    {
      cnt++;
    }
  }
  if(len==1)//1输出的是0
  {
    ans=0;
  }
  else if(cnt==1)//只有一个1,则说明是2的幂
  {
    ans=len/2;
  }
  else
  {
    ans=(len+1)/2;
  }
  cout<<ans<<endl;
  return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值