Advertisement
jasonpogi1669

Find First and Last Indices of a Character using C++

Sep 21st, 2021 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios::sync_with_stdio(false);
  7.     cin.tie(0);
  8.     string s = "01010010101";
  9.     int first = s.find('0');
  10.     int last = s.rfind('0');
  11.     cout << first << " " << last << '\n';
  12.     return 0;
  13. }
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement