North North West
Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB
Total submit users: 71, Accepted users: 59
Problem 13406 : No special judgement
Problem description

We can describe detailed direction by repeating the directional names: north, south, east and west. For example, northwest is the direction halfway between north and west, and northnorth- west is between north and northwest.

In
this problem, we describe more detailed direction between north and west as
follows.

• “north” means 0 degrees.

• “west” means 90
degrees.

• If the direction dir means a degrees and the sum of the
occurrences of “north” and “west” in dir is n (≥ 1), “north”dir (the
concatenation of “north” and dir) means a−90/(2^n) degrees and “west”dir means a
+90/(2^n) degrees.

Your task is to calculate the angle in degrees
described by the given direction.

Input

The input contains several datasets. The number of datasets does not exceed
100.

Each dataset is described by a single line that contains a string
denoting a direction. You may assume the given string can be obtained by
concatenating some “north” and “west”, the sum of the occurrences of “north” and
“west” in the given string is between 1 and 20, inclusive, and the angle denoted
by the given direction is between 0 and 90, inclusive. The final dataset is
followed by a single line containing only a single “#”.

Output

For each dataset, print an integer if the angle described by the given
direction can be represented as an integer, otherwise print it as an irreducible
fraction. Follow the format of the sample output.

Sample Input
north
west
northwest
northnorthwest
westwestwestnorth
#
Sample Output
0
90
45
45/2
315/4
Problem Source
JAG Practice Contest for ACM-ICPC Asia Regional 2014
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int gcd(int x,int y)
{
if(y%x==)return x;
return gcd(y%x,x);
}
int main (void)
{
int n,m,i,j,k,l;
char str[];
int s[];
while(gets(str)&&str[]!='#')
{
l=;
for(i=;str[i];i++)
if(str[i]=='n')
{
s[l++]=;
i+=;
}else
{
s[l++]=-;
i+=;
}
int x,y;
y=;
if(s[--l]==)
{
x=;
}else
{
x=;
}
k=;
while(l--)
{
x*=;
y*=;
k*=;
if(s[l]==)x-=;
else x+=;
}
int g;
if(x%y==)
printf("%d\n",x/y);
else
{
g=gcd(x,y);
printf("%d/%d\n",x/g,y/g);
} ; }
return ;
}

North North West的更多相关文章

  1. CodeFroces--Good Bye 2016-B--New Year and North Pole(水题-模拟)

    B. New Year and North Pole time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  2. 【codeforces 750B】New Year and North Pole

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. swift-闭包(代码块)

    语法 通用的语法 {(parameters) -> return type in statements } e.g let studname = { println("Welcome ...

  4. Windows Azure Storage (17) Azure Storage读取访问地域冗余(Read Access – Geo Redundant Storage, RA-GRS)

    <Windows Azure Platform 系列文章目录> 细心的用户会发现,微软在国外和国内的数据中心建设都是成对的,比如香港数据中心(Asia East)和新加坡的数据中心(Sou ...

  5. ExtJs布局详解

    序言 1.百度百科上说:ExtJs功能丰富,无人能出其右.无论是界面之美,还是功能之强,extjs都高居榜首. 2.呵呵,界面之美当是少不了布局的,这篇文章我写layout的七种布局.(extjs是4 ...

  6. silicon labs 代理商

      http://www.silabs.com/buysample/pages/contact-sales.aspx?SearchLocation=China       Silicon Labs A ...

  7. java布局学习 (一)

    Java 程序通过jvm可以很好的移植到其他平台上,但是java 生成的图形界面样式,在不使用布局的情况下,往往需要重新设定大小,才能在新的平台上调整到最佳样式.这是由于组件的最佳大小 往往是与平台相 ...

  8. Swift2.3 --> Swift3.0 的变化

    Swift3.0语法变化 首先和大家分享一下学习新语法的技巧: 用Xcode8打开自己的Swift2.3的项目,选择Edit->Convert->To Current Swift Synt ...

  9. Draw_extend使用OpenGL显示数据点

    //alter load_map.dev //safety verion 2016/1/12 #include <iostream> #include <fstream> #i ...

随机推荐

  1. 实现一个div在浏览器水平居中

    第一种方法: div { margin: 0 auto; width: 960px; } 第二种方法(兼容IE): body { text-align: center; } div { margin: ...

  2. javascript检测是否安装了flash

    检测是否安装了flash function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版 ...

  3. linux sed命令学习

    . Sed简介 . 定址 . Sed命令 . 选项 . 元字符集 . 实例 . 脚本 . 小技巧 . Sed简介 sed是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中, ...

  4. 【BZOJ】1006: [HNOI2008]神奇的国度 弦图消除完美序列问题

    1006: [HNOI2008]神奇的国度 Description K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则. 他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的 ...

  5. <三> SQL杂七杂八

    批量插入测试数据 use Testdeclare @count INTset @count = 0while(@count < 10)begin waitfor delay '000:00:10 ...

  6. js格式化数字 金额按千位逗号分隔

    // 返回数字 function removeFormatMoney(s) { return parseFloat(s.replace(/[^\d\.-]/g, "")); } / ...

  7. jQuery中的一些正则匹配表达式

    jQuery常用正则匹配表达式 落雨 //整数 "^-?[1-9]\\d*$", //正整数 "^[1-9]\\d*$", //负整数 intege2: &qu ...

  8. 1007: [HNOI2008]水平可见直线

    先对a排序,a相等的话就对b排序: 维护一个栈,每次取栈的头两个,和当前的直线相比较: 如果当前的直线把头第一个屏蔽,就将他出栈,一直到不能屏蔽为止: 代码: #include<cstdio&g ...

  9. Unity3D热更新

    原地址:http://crazylights.cnblogs.com/ 下载在这个时代实在是太平常了,每个人都深刻的理解着下载到底是什么. 这一篇文字只是把下载的代码分享并介绍,而已. 首先,下载系统 ...

  10. 继续完成昨天的第一个点:更改DJANGO的ADMIN后台的表单显示

    遇到的问题是MANYTOMANY的选项太多,默认的DJANGO一个多选框搞得人蛋疼, 于是作了一个扩展,不是最好的,但方便多啦.. 也是在昨天说过的各个app的admin.py里操作: from dj ...