fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fi first
  4. #define se second
  5. #define pb push_back
  6. #define mp make_pair
  7. #define inf 1000000005
  8. #define all(a) (a).begin(), (a).end()
  9. #define ms(a,x) memset(a, x, sizeof(a))
  10. /* #define mod 1000000007 */
  11. #define sz(a) ((int)(a).size())
  12.  
  13. template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
  14. template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
  15. template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
  16. template<class T> int cntbit(T s) { return __builtin_popcountll(s);}
  17. #define Rep(i,n) for(int i = 0; i < (n); ++i)
  18. #define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
  19. #define For(i,a,b) for(int i = (a); i <= (b); ++i)
  20. #define Ford(i,a,b) for(int i = (a); i >= (b); --i)
  21.  
  22. typedef unsigned long long ull;
  23. typedef long long ll;
  24. typedef long double ld;
  25. #define eps 1e-6
  26. typedef pair<int, int> II;
  27. template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
  28. template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
  29. #define PI 2 * acos(0)
  30. #define maxn 1000025
  31. #define maxm 30000005
  32.  
  33. string s;
  34. ll n;
  35. ld nH = 0, nU = 0;
  36.  
  37. void sol(){
  38. ios_base::sync_with_stdio(false);
  39. cin.tie(NULL);
  40.  
  41. cin >> s;
  42. n = sz(s);
  43. ld res = 0;
  44. For(i, 1, n){
  45. char c = s[i - 1];
  46. if(c == 'H'){
  47. res += i + i;
  48. nH++;
  49. } else if(c == '?'){
  50. res += i;
  51. nU++;
  52. }
  53. }
  54. res -= (nH * nH + nH * nU + nU * (nU + 1) / 4);
  55.  
  56. cout << fixed << setprecision(1) << res << endl;
  57. }
  58.  
  59. int main(){
  60. sol();
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0s 4536KB
stdin
Standard input is empty
stdout
0.0