Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int find_nearest_pair(string const& str, char first, char second)
- {
- int min_distance = str.length();
- int pos_first = str.find(first);
- while (pos_first != str.npos){
- if (int pos_second = str.find(second, pos_first + 1)){
- if(pos_second != str.npos){
- if(int distance = pos_second - pos_first){
- if(distance < min_distance){
- min_distance = distance;
- }
- }
- }
- }
- pos_first = str.find(first, pos_first + 1);
- }
- return min_distance == str.length() ? -1 : min_distance - 1;
- }
- int main(){
- string napis;
- char p,k;
- cin>>napis;
- cin>>p>>k;
- cout<<find_nearest_pair(napis,p,k);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement