fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4. #include <algorithm>
  5.  
  6. int main() {
  7. std::string s;
  8. std::cin >> s;
  9. std::regex r("(?=([^*][*]*[^*]))");
  10.  
  11. int best = s.size();
  12. for (auto i = std::sregex_iterator(s.begin(), s.end(), r); i != std::sregex_iterator(); ++i) {
  13. int pos = i->position(1);
  14. int len = i->length(1);
  15. if (s[pos] != s[pos + len -1]) {
  16. best = std::min(len-2, best);
  17. }
  18. }
  19. std::cout << best;
  20. return 0;
  21. }
Success #stdin #stdout 0s 16152KB
stdin
A*A**B***A**
stdout
2