Weather Station

来源:互联网 发布:西装定制 知乎 编辑:程序博客网 时间:2024/06/05 11:54
Albert is a well-known inventor. He’s the one who designed an electronic weather 
station that periodically track all kinds of weather parameters and records the results 
of its measurements. While scanning the records made by the weather station, Albert 
discovered one important omission: wind direction data were recorded in one line 
without any separator characters. Albert became curious how many different 
solutions there would be if he tried to restore the original sequence of measurements.
The inventor wanted you to know that the station distinguishes eight different wind 
directions and encodes each one of them with one or two characters. In addition, he 
has drawn a picture with wind direction notations used by the weather station.
Your task is to write a program that will calculate the number 
of original sequences for a specific record based on weather 
station data. Albert realizes that the resulting number may be 
quite large, so your task is merely to calculate the value 
9
modulo 10 ?+?7.
Limitations
5
The length of the input line does not exceed 10 .
Input
The input file consists of a single line that contains a record made by the weather 
station. The record is a line of wind direction values containing characters N, S, W, 
and E. 
Output
9
Output file must contain integer number of possible solutions modulo 10 ?+?7.
Examples
Input.txt Output.txt
NEWS 2
EWNS 1
Note
The line in the first example has two solutions: {N, E, W, S} and {NE, W, S}.

The line in the second example has one solution: {E, W, N, S}.

题意:一个气象站观测风向,风向有八个n,w,s,e,nw,ne,sw,se

给你一串字符中间没有空格和其他字符问一共有多少种风向情况

思路:遍历一遍字符串,w,e没用,当遍历到s,n时如果后边含有w或者e乘2,边算边取余

ac代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>const long long maxn=1000000007;using namespace std;int main(){    freopen("input.txt","r",stdin);    freopen("output.txt","w",stdout);    char a[100005];    while(gets(a))    {        int len=strlen(a);        long long sum=1;        for(int i=0;i<len;i++)        {          if(a[i]=='N')          {              if(a[i+1]=='E'||a[i+1]=='W')              {sum=(sum*2)%maxn;              i++;              }          }          if(a[i]=='S')          {              if(a[i+1]=='E'||a[i+1]=='W')              {                  sum=(sum*2)%maxn;                  i++;              }          }        }        printf("%lld\n",sum);    }    return 0;}

0 0
原创粉丝点击