F. Set the memory
2016-04-20 20:13
330 查看
F. Set the memory
Time Limit: 1000msMemory 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 ss 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); } }
相关文章推荐
- C#中的委托和事件
- 快速排序法
- ZOJ 3785 What day is that day?【思维+递推循环节】
- 获取java方法签名
- iOS 动画Animation - 6 - 1:实战练习之圆弧下拉动效
- KMP算法详解
- iOS开发之OC最常见面试题总结
- 网络:NSURLSession 下载文件
- 关于Grid的自动化测试
- POJ 3420 Quad Tiling
- android的消息处理机制(图+源码分析)——Looper,Handler,Message
- sublime中使用python3(windows环境)
- python中的转义字符
- 查看关于yum的配置
- Java反射实现接口
- intent传递有没有大小限制,是多少?
- (C#)WinForm窗体间传值
- CSRF 批量进行校验
- LeetCode-342. Power of Four
- 插入排序法