Codeforces Round #157 (Div. 1)---A. Little Elephant and Bits

本文介绍如何在给定的二进制数中删除一位后,获取最大的二进制数,并通过示例解释了解题思路及AC代码。

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105digits.

Output

In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.

Sample test(s)
input
101
output
11
input
110010
output
11010
Note

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; 
} 





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值