题目链接:https://vjudge.net/problem/Gym-101243D 题意:给你一段字符串,这段字符串有各种风向组成(N,NE,E,SE,S,SW,W,NW),让你判断这串字符串有几种组合可能 解析:遇到N和S的时候,判断下一个字符是否是W或E,是的话答案就乘二,其实也就是选或不选的情况
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
const int maxn =
1e5+
100;
const int mod =
1e9+
7;
char a[maxn];
int main()
{
freopen(
"input.txt",
"r",stdin);
freopen(
"output.txt",
"w",stdout);
scanf(
"%s",a);
int len =
strlen(a);
long long ans =
1;
for(
int i=
0;i<len;i++)
{
if(a[i]==
'N' || a[i]==
'S')
{
if(a[i+
1]==
'W'||a[i+
1]==
'E')
{
ans = (ans*
2)%mod;
i++;
}
}
}
printf(
"%I64d\n",ans);
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-20153.html