Problem A. Lazy Spelling Bee Google APAC 2017 University Test Practice Round

    xiaoxiao2021-03-26  35

    这一题只要判断一下i,i-1,i+1位置处有多少个不同的字母就可以了。注意首尾两端要特判一下。

    #include<iostream> #include<stdio.h> #include<cstdio> #include<stdlib.h> #include<vector> #include<string> #include<cstring> #include<cmath> #include<algorithm> #include<stack> #include<queue> #include<ctype.h> #include<map> #include<time.h> #include<set> #include<bitset> #include<sstream> using namespace std; //Google APAC2017 Practice Round Problem A. Lazy Spelling Bee const long long mod=1e9+7; const int maxn=1010;//lead to WA it set it as 1000, since need end symbol int T; char w[maxn]; long long ans; int combnum(int idx) { if(idx==0) { if(w[idx]==w[idx+1]) { return 1; } else { return 2; } } else if(idx==strlen(w)-1) { if(w[idx]==w[idx-1]) { return 1; } else { return 2; } } else { set<char>letter; letter.clear(); letter.insert(w[idx-1]); letter.insert(w[idx]); letter.insert(w[idx+1]); return letter.size(); } } int main() { freopen("A-large-practice.in","r",stdin); freopen("A-large-practice.out","w",stdout); scanf("%d",&T); for(int ca=1;ca<=T;ca++) { scanf("%s",w); int len=strlen(w); ans=1; if(len==1) { ans=1; } else { for(int i=0;i<len;i++) { // ans=(ans%mod)*(combnum(i)%mod); ans=ans*combnum(i); ans%=mod; } } printf("Case #%d: %lld\n",ca,ans); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-661959.html

    最新回复(0)