A. inc ARG
来源:互联网 发布:js file文件上传 编辑:程序博客网 时间:2024/05/18 02:37
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the n-th bit.
Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded.
Sergey wrote certain values of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of bits in the cell.
The second line contains a string consisting of n characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
41100
3
41111
4
In the first sample the cell ends up with value 0010, in the second sample — with 0000.
解题说明:此题是一道模拟题,对一个二进制数加一,问有多少位数字发生改变,类似于余码的加法。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<cmath>using namespace std;char a[108];int main(){int n,i,sum;scanf("%d",&n);scanf("%s",a);sum=0;for(i=0;i<n;i++){if(a[i]=='1'){sum++;}if(a[i]=='0'){sum++;break;}}printf("%d\n",sum);return 0;}
- A. inc ARG
- CodeForces 465A inc ARG
- Codeforces 465A inc ARG
- Codeforces-465A-inc ARG
- codeforces-#465A. inc ARG(模拟)
- Codeforces 465A inc ARG(水题)
- Codeforces Round #265 (div2) A. inc ARG
- Codeforces Round #265 (Div. 2) 465A. inc ARG(数学题)
- Codeforces Round #265 (Div. 2) A. inc ARG
- java.lang.IllegalStateException: @Resource annotation requires a single-arg method
- bootloader之memcfg.inc 或memcfg.s memcfg.a
- python中 *arg,**arg
- 再谈*arg或**arg
- arg 和 arg max
- 050-832-(565) also called cni-networking technologies is a Novell,Inc exam of Novell, Inc company.
- ..\common\inc;.\inc很重要
- Resolving: java.sql.Timestamp does not have a no-arg default constructor
- how to solve "java.sql.Timestamp does not have a no-arg default constructor" ?
- CRM2011分布式安装:产品密钥与安装的Microsoft Dynamics CRM版本不兼容
- drools读取规则
- android开发工程师
- linux下删除目录下的所有.svn
- Android 通过WebService调用天气预报接口
- A. inc ARG
- html5兼容低版本浏览器
- linux内存管理之存储器区域
- Same Tree
- java web 学习总结
- JS获取地址栏参数的方法【推荐】
- 用ArcGIS Spatial Analyst 扩展模块可以做些什么
- drools 规则获取
- RDF Refine(Open Refine + RDF Refine)使用笔记