Codeforces Round #157 (Div. 1)---A. Little Elephant and Bits
来源:互联网 发布:奢侈品包 知乎 编辑:程序博客网 时间:2024/05/21 09:33
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
101
11
110010
11010
In the first sample the best strategy is to delete the second digit. That results in number 112 = 310.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
解题思路:给一个二进制数,让你任意删一个数字之后,问能得到的最大数为多少。
也算贪心吧,我们遍历直接记录第一个‘0’的位置,然后输出的时候,直接把第一个‘0’略过不输出即可,若序列中全为‘1’时, 输出的时候直接输出(n-1)个‘1’即可。
AC代码:
#include <iostream>#include <cstdio>#include <string>#include <algorithm>using namespace std;int main(){//freopen("in.txt", "r",stdin);string s;while(cin>>s){int len = s.size();int t = 0;for(int i=0; i<len; i++){if(s[i] == '0') { t = i; //找到第一个‘0’的位置break;} }for(int i=0; i<len; i++){ if(i == t) continue;cout<<s[i];}cout<<endl;}return 0; }
- Codeforces Round #157 (Div. 1)---A. Little Elephant and Bits
- Codeforces Round #129 (Div. 1) A Little Elephant and Interval
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections
- Codeforces Round #129 (Div. 2)A. Little Elephant and Rozdil
- Codeforces Round #136 (Div. 2) A. Little Elephant and Function
- Codeforces Round #129 (Div. 1) B. Little Elephant and Cards
- Codeforces Round #129 (Div. 1) B. Little Elephant and Cards
- Codeforces Round #136 (Div. 1) B. Little Elephant and Array
- Codeforces Round #129 (Div. 1)E. Little Elephant and Strings
- Codeforces Round #136 (Div. 1) B. Little Elephant and Array
- codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
- A. Little Elephant and Bits
- A. Little Elephant and Bits
- Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (数学、dp)
- Codeforces Round #157 (Div. 1)B. Little Elephant and Elections 数位dp好
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp
- (Codeforces Round #136 (Div. 2))A. Little Elephant and Function(递归分析,简单)
- Codeforces Round #136 (Div. 2) / 221A Little Elephant and Function (数学)
- JDBC
- 百度风云榜样式
- windows程序设计(第五版珍藏版)清华大学出版
- eclipse svn 忽略 target目录 and so on (zz)
- SQL有鸡兔同笼
- Codeforces Round #157 (Div. 1)---A. Little Elephant and Bits
- CVPixelBufferLockBaseAddress
- SQL求aX2+bX+c=0的根
- Echarts柱状图
- C++类构造函数初始化列表,子类向父类传参数
- hybris 5.3上启用hybris B2C Accelerator for China体验B2C网站
- SQL求圆的面积、周长,已知半径 r=10
- Head First Python (中文)学习笔记-第3章
- Andorid linux模块编译和加载(三)