题目地址:点击打开链接
思路:任意一个字符串都是由最初的第零个和第一个构成的,只要记录含有的第零个和第一个字符串的个数即可
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
typedef long long ll;
using namespace std;
struct node
{
int x;
int y;
}a[60];
char str1[40];
char str2[40];
int num[40];
int num1[40];
int main()
{
int t,k,i;
scanf("%d",&t);
while(t--)
{
memset(num,0,sizeof(num));
memset(num1,0,sizeof(num1));
scanf("%s%s",str1,str2);
scanf("%d",&k);
a[0].x = 1;
a[0].y = 0;
a[1].x = 0;
a[1].y = 1;
for(i=2; i<=k; i++)
{
a[i].x = a[i-1].x + a[i-2].x;
a[i].y = a[i-1].y + a[i-2].y;
}
int n = strlen(str1);
int m = strlen(str2);
for(i=0; i<n; i++)
{
num[str1[i]-'a']++;
}
for(i=0; i<26; i++)
{
num[i] *= a[k].x;
}
for(i=0; i<m; i++)
{
num1[str2[i]-'a']++;
}
for(i=0; i<26; i++)
{
num1[i] *= a[k].y;
}
for(i=0; i<26; i++)
{
num[i] += num1[i];
}
for(i=0; i<26; i++)
{
printf("%c:%d\n",'a'+i,num[i]);
}
printf("\n");
}
return 0;
}