您的位置:首页 > 其它

F. Set the memory

2016-04-20 20:13 330 查看

F. Set the memory

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld Java class name:
Main

Submit

Status
PID: 4054

You have been given a very strange computer. Its memory consists of several bits, each initially set to 0, and it can perform only one type of operation: Choose one of the bits in memory, and choose a value - 0 or 1. All the bits between the selected bit
and the last bit in memory, inclusive, will be set to the chosen value. For example, if the memory is "0010", and you choose the second bit and a value of 1, the memory will change to "0111". You are given a string s. The number of characters in s is equal
to the number of bits in the computer's memory. calculate the minimum number of operations required to set the computer's memory equal to s.

Input

Only one line : the string s

s will contain between 1 and 10,000 characters, inclusive.

s will contain only the characters '0' (zero) or '1' (one).

请使用scanf("%s")读入

Output

minimum number of operations required to set the computer's memory equal to s.

Sample Input

0100

Sample Output

2

Hint

The operations of the Sample:

0000 -> 0111 -> 0100

#include<stdio.h>
#include<string.h>
int main()
{
char a[100000];
int l,i,j;
while(scanf("%s",a)!=-1)
{
int h;
l=strlen(a);
for(i=0; i<l; i++)
{
if(a[i]=='1')
{
h=i;
break;
}
}
int k=0;
for(i=h; i<l; i++)//前面和后边不一样就加一
{
if(a[i]!=a[i+1])
{
k++;
}
}
printf("%d\n",k);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: