North North West

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==0)return x;
    return gcd(y%x,x);
}
int main (void)
{
    int n,m,i,j,k,l;
    char str[11111];
    int s[11111];
    while(gets(str)&&str[0]!=‘#‘)
    {
        l=0;
        for(i=0;str[i];i++)
        if(str[i]==‘n‘)
        {
            s[l++]=1;
            i+=4;
        }else
        {
            s[l++]=-1;
            i+=3;
        }
        int x,y;
        y=1;
        if(s[--l]==1)
        {
            x=0;
        }else
        {
            x=90;
        }
        k=1;
        while(l--)
        {
            x*=2;
            y*=2;
            k*=2;
            if(s[l]==1)x-=90;
            else x+=90;
        }
        int g;
        if(x%y==0)
           printf("%d\n",x/y);
         else
         {
             g=gcd(x,y);
             printf("%d/%d\n",x/g,y/g);
         }

 ;   }
    return 0;
}
时间: 2024-10-12 15:55:03

North North West的相关文章

强大的pdf文件操作小工具——PDFtk的小白用法

前言 作为程序员,大家都知道的,总是会被技术小白问各种跟编程没什么关系的硬件.软件问题.曾经被一技术小白同事问到有没有什么办法合并pdf文件,当时自己也是一头雾水,因为自己工作生活很少会去操作pdf文件,而当时公司对开发人员的电脑权限管理很严格,不论是上网还是安装软件,都受到很大限制,最后硬着头皮忙活了一阵子也没在解决. 前两天在写批处理程序的时候,发现批处理程序是有合并文件的命令的,我忽然想起之前这个同事的问题,就试了一下合并pdf,然而并不行.虽然失落了一下,但本着学习的精神还是百度了一下关

HDU4452 Running Rabbits

涉及知识点: 1. direction数组. 2. 一一映射(哈希). Running Rabbits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1565    Accepted Submission(s): 1099 Problem Description Rabbit Tom and rabbit Jerry are runn

6.面向对象程序设计(2)

view包 1 package view; 2 3 import java.awt.event.MouseAdapter; 4 import java.awt.event.MouseEvent; 5 6 import javax.swing.ImageIcon; 7 import javax.swing.JFrame; 8 import javax.swing.JLabel; 9 10 @SuppressWarnings("serial") 11 public class QqClie

Java编程思想读书笔记

声明:原创作品,转载时请注明文章来自SAP师太技术博客:www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4290955.html 第一章对象导论... 1 第二章一切都是对象... 4 第三章操作符... 10 第四章流程控制... 12 第五章初始化与清理... 14 第六章访问权限控制... 15 第七章复用... 23 第八章多态... 2

The 2014 ACMICPC Asia Regional Guangzhou Online

这场网赛当时自己完成了的也就是两道地图题,过去好久了才想到还是该记录下来... [C] Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) [Problem Description] <Dream of the Red Chamber>(also <The Story of the Stone>) is one of

hdu 5024 Wang Xifeng&#39;s Little Plot (dfs+暴力)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 194    Accepted Submission(s): 131 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

HDU 5024 Wang Xifeng&#39;s Little Plot (搜索)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 157    Accepted Submission(s): 105 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

POJ 1736 Robot BFS

Robot Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7561   Accepted: 2444 Description The Robot Moving Institute is using a robot in their local store to transport different items. Of course the robot should spend only the minimum time

swift基础学习(04)[闭包、函数、枚举、类和结构体]

//闭包表达式:闭包表达式是一种利用简洁语法构建内联闭包的方式 //sort方法:排序功能,排序后的原来的不会被修改 //:从大到小排序 let names = ["d","ds","wa","ad"] func sortNames(sName1:String,sName2:String) -> Bool { return sName1 > sName2 } var result = names.sort(sort