読者です 読者をやめる 読者になる 読者になる

JAG夏合宿2014 3日目 A - North North West

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a; i<(int)b; i++)
#define rep(i,n) REP(i,0,n)

int main() {
  
  string str;
  while(cin >> str) {
    if(str == "#") break;
    vector<int> order;
    rep(i, str.size()) {
      if(str[i] == 'n') { order.push_back(0); }
      if(str[i] == 'w') { order.push_back(1); }
    }
    reverse(order.begin(), order.end());
    int nume = 0;
    int deno = 1<<order.size();
    int ncnt = 0, wcnt = 0;
    rep(i, order.size()) {
      if(order[i] == 0) {
        if(i) {
          nume -= 90 * (deno / (1<<(ncnt+wcnt)));
        }
        ncnt ++;
      }
      else {
        nume += 90 * (deno / (1<<(ncnt+wcnt)));
        wcnt ++;
      }
    }
    int GCD = __gcd(nume, deno);
    nume /= GCD;
    deno /= GCD;
    cout << nume;
    if(deno > 1) {
      cout << "/" << deno;
    }
    cout << endl;
  }
  
  return 0;
}