3

Google APAC 2017 Problem A. Lazy Spelling Bee(模拟)

 3 years ago
source link: https://arminli.com/google-apac-2017-a/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Armin's Blog

Google APAC 2017 Problem A. Lazy Spelling Bee(模拟)

August 28, 2016

题目链接

题意:给 一个长度为 L 的字符串,问能求出多少个长度为 L 的字符串,使得输出的字符串 i 位与原字符串 i-1、i、i+1 位的任意一位字符相等。

直接扫一遍乘一起取模就可以,注意开 longlong。

#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int mod = 1e9+7;
int main(){
	freopen("../Downloads/A-large-practice.in", "r", stdin);
	freopen("ans.out", "w", stdout);
	int t; cin >> t;
	for(int cas = 1; cas <= t; cas++){
		char s[1005];
		scanf("%s", s);
		int len = strlen(s);
		long long ans = 1;
		for(int i = 0; i < len; i++){
			int tmp = 1;
			if(i == 0){
				if(i+1<len && s[i]!=s[i+1]) tmp++;
			}else if (i == len-1){
				if(s[i] != s[i-1]) tmp++;
			}else{
				if(s[i] != s[i-1]) tmp++;
				if(s[i+1]!=s[i] && s[i+1]!=s[i-1]) tmp++;
			}
			ans =(ans*tmp)%mod;
		}
		printf("Case #%d: %lld\n", cas, ans);
	}
	return 0;
}

注意这个平台需要提交的是输出的文本,而不是代码……


Profile picture

Written by Armin Li , a venture capitalist. [Weibo] [Subscribe]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK