zoukankan      html  css  js  c++  java
  • 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
    ",x/y);
             else
             {
                 g=gcd(x,y);
                 printf("%d/%d
    ",x/g,y/g);
             }
    
     ;   }
        return 0;
    }
  • 相关阅读:
    【Visual C++】游戏开发笔记之六——游戏画面绘图(三)透明特效的制作方法
    【不定期更新】游戏开发中的一些良好习惯与技术技巧
    【Visual C++】游戏开发笔记之七——基础动画显示(一)定时器的使用
    【超级经典】程序员装B指南(转)
    Gentoo安装小记
    图形学中的贴图采样、走样与反走样等
    面试题之银行业务调度系统
    四川雅安芦山加油挺住
    ZOJ 3223 Journey to the Center of the Earth
    android中ListView拖动时背景黑色的问题
  • 原文地址:https://www.cnblogs.com/cancangood/p/4734886.html
Copyright © 2011-2022 走看看