Aman jain
BAN USERwanna google or facebook.
@rahul(imrhk) its working fine on my machine ans for ur string is 4.
@niraj,nijju: i think we need to find first occurence of 1 using bsearch. According to that if input string does not contain 1 then it should print something like this for ex:1 is not in string.
// AUTHOR: AMAN JAIN
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <deque>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <vector>
#include <queue>
#define sz(s) s.size()
using namespace std;
int search(string& s,int low,int high){
if(low>high)return -1;
int mid=low+(high-low)/2;
int po=search(s,low,mid-1);
if(po!=-1)return po;
if(s[mid]=='1')return mid;
po=search(s,mid+1,high);
if(po!=-1)return po;
return -1;
}
int main(){
string s;
cin>>s;
int po=search(s,0,sz(s)-1);
if(po!=-1)cout<<po<<"\n";
else printf("1 is not in string\n");
return 0;
}
Repberrysvickers, Associate at Absolute Softech Ltd
Spent 2001-2004 developing strategies for country Luxury Car Rental Miami. Had some great experience building robots for the underprivileged. Have ...
- Aman jain June 01, 2013