fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fast_io ios::sync_with_stdio(false); cin.tie(NULL)
  5. #define int long long
  6.  
  7. void solve() {
  8. string s;
  9. cin >> s;
  10. int n = s.size();
  11.  
  12. if (s[0] != '<' || s[n-1] != '>') {
  13. cout << -1 << "\n";
  14. return;
  15. }
  16.  
  17. int pref = 0;
  18. while (pref < n && s[pref] == '>') pref++;
  19.  
  20. int suf = 0;
  21. while (suf < n && s[n-1-suf] == '<') suf++;
  22.  
  23. cout << max(pref, suf) << "\n";
  24. }
  25.  
  26. int32_t main() {
  27. fast_io;
  28. int t;
  29. cin >> t;
  30. while (t--) solve();
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 5316KB
stdin
4
*****
<<<>
>*<
*
stdout
-1
0
-1
-1