Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. //#include <cstdint>
  2. #include <cstdlib>
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <iomanip>
  6. #include <fstream>
  7. #include <list>
  8. #include <string>
  9. #include <vector>
  10. #include <sstream>
  11. #include <set>
  12. #include <queue>
  13. #include <stack>
  14. #include <map>
  15. #include <cmath>
  16. // hey my dear c++03 compiler how are you
  17. #include <functional>
  18. //#include <random>
  19.  
  20. #define range(a) (a).begin(),(a).end()
  21. #define rrange(a) (a).rbegin(),(a).rend()
  22. typedef long long long64;
  23. typedef long long int64;
  24. using namespace std;
  25.  
  26. inline double sqr(double a) { return a * a; }
  27.  
  28.  
  29.  
  30.  
  31.  
  32. int main()
  33. {
  34.     freopen("input.txt", "r", stdin);
  35.     int n;
  36.     string s;
  37.     cin >> n >> s;
  38.     int64 ans = 0;
  39.     int64 la=n - 1, ff=0;
  40.     for (int64 i = 0; i < n; i++)
  41.     {
  42.  
  43.         for (; la >= 0; la--)
  44.         {
  45.             if (s[la] == 'A')
  46.                 break;
  47.         }
  48.         for (; ff<n; ff++)
  49.         {
  50.             if (s[ff] == 'F')
  51.                 break;
  52.         }
  53.  
  54.         if (ff > la)
  55.         {
  56.             break;
  57.         }
  58.  
  59.         for (int64 f=ff; f<la; f++)
  60.         {
  61.             swap(s[f], s[f+1]);
  62.             ans++;
  63.         }
  64.  
  65.         la--;
  66.         la--;
  67.     }
  68.     cout << ans;
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement