Fibonacci String

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5008    Accepted Submission(s): 1690

Problem Description
After little Jim learned Fibonacci Number in the class , he was very interest in it.
Now he is thinking about a new thing -- Fibonacci String .

He defines : str[n] = str[n-1] + str[n-2] ( n > 1 ) 

He is so crazying that if someone gives him two strings str[0] and str[1], he will calculate the str[2],str[3],str[4] , str[5].... 

For example :
If str[0] = "ab"; str[1] = "bc";
he will get the result , str[2]="abbc", str[3]="bcabbc" , str[4]="abbcbcabbc" …………;

As the string is too long ,Jim can't write down all the strings in paper. So he just want to know how many times each letter appears in Kth Fibonacci String . Can you help him ?
 
Input
The first line contains a integer N which indicates the number of test cases.
Then N cases follow.
In each case,there are two strings str[0], str[1] and a integer K (0 <= K < 50) which are separated by a blank.
The string in the input will only contains less than 30 low-case letters.
 
Output
For each case,you should count how many times each letter appears in the Kth Fibonacci String and print out them in the format "X:N". 
If you still have some questions, look the sample output carefully.
Please output a blank line after each test case.

To make the problem easier, you can assume the result will in the range of int. 
Sample Input
1
ab bc 3
Sample Output
a:1
b:3
c:2
d:0
e:0
f:0
g:0
h:0
i:0
j:0
k:0
l:0
m:0
n:0
o:0
p:0
q:0
r:0
s:0
t:0
u:0
v:0
w:0
x:0
y:0
z:0
 Author
linle
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1709 1710 1711 1707 1701 
 
水题,简单的递推。
 1 #include<iostream>
2 #include<string.h>
3 #include<queue>
4 #include<stdio.h>
5 #include<algorithm>
6 using namespace std;
7 char a[40];
8 char b[40];
9 int aa[26];
10 int bb[26];
11 int cc[26];
12 int main(void)
13 {
14 int n,i,j,k,p,q;
15 scanf("%d",&k);
16 while(k--)
17 {
18 scanf("%s %s",a,b);
19 memset(aa,0,sizeof(aa));
20 memset(bb,0,sizeof(bb));
21 scanf("%d",&p);
22 int l=strlen(a);
23 int r=strlen(b);
24 for(i=0;i<l;i++)
25 {aa[a[i]-'a']+=1;
26 }
27
28 for(i=0;i<r;i++)
29 {
30 bb[b[i]-'a']+=1;
31 }
32 if(p==0)
33 {
34 for(i=0;i<=25;i++)
35 {
36 printf("%c:",i+'a');
37 printf("%d\n",aa[i]);
38 }
39 }
40 else if(p==1)
41 {
42 for(i=0;i<=25;i++)
43 {
44 printf("%c:",i+'a');
45 printf("%d\n",bb[i]);
46 }
47 }
48 else
49 {
50 for(i=0;i<p-1;i++)
51 {
52 for(j=0;j<=25;j++)
53 {
54 cc[j]=aa[j]+bb[j];
55 }
56 for(j=0;j<=25;j++)
57 {
58 aa[j]=bb[j];
59 }
60 for(j=0;j<=25;j++)
61 {
62 bb[j]=cc[j];
63 }
64 }
65 for(i=0;i<=25;i++)
66 {
67 printf("%c:",i+'a');
68 printf("%d\n",cc[i]);
69 }
70 }printf("\n");
71
72 }
73 return 0;
74 }

Fibonacci String(hdu 1708)的更多相关文章

  1. HDU 1708 简单dp问题 Fibonacci String

    Fibonacci String Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. hdu 1708 Fibonacci String

    Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDOJ(HDU) 1708 Fibonacci String

    Problem Description After little Jim learned Fibonacci Number in the class , he was very interest in ...

  4. String HDU 5672(双指针)

    String HDU 5672(双指针) 传送门 题意:一个字符串中找到所有拥有不少于k个不同的字符的子串. import java.io.*; import java.util.*; public ...

  5. Combine String HDU - 5707 dp or 广搜

    Combine String HDU - 5707 题目大意:给你三个串a,b,c,问a和b是不是恰好能组成c,也就是a,b是不是c的两个互补的子序列. 根据题意就可以知道对于c的第一个就应该是a第一 ...

  6. (KMP)Count the string -- hdu -- 3336

    http://acm.hdu.edu.cn/showproblem.php?pid=3336 Count the string Time Limit: 2000/1000 MS (Java/Other ...

  7. (字符串) Hidden String -- HDU -- 5311

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5311 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  8. HDU 1708

    思路 :二位数组维护数目. #include<iostream> #include<stdio.h> #include<stdlib.h> #include< ...

  9. Count the string - HDU 3336(next+dp)

    题目大意:给你一个串求出来这个串所有的前缀串并且与前缀串相等的数量,比如: ababa 前缀串{"a", "ab", "aba", &quo ...

随机推荐

  1. 给lua_close实现回调函数

    先讲下为什么会需要lua_close回调吧. 我用C++给lua写过不少库,其中有一些,是C++依赖堆内存,并且是每一个lua对象使用一块单独的内存来使用的. 在之前,我一直都是魔改lua源代码,给l ...

  2. linux 实用指令时间日期类

    linux 使用指令时间日期类 data 显示当前日期 基本语法 date 显示当前时间 date+%Y 显示当前年份 date+%m 显示当前月份 date+%d 显示当前是哪一天 date &qu ...

  3. A Child's History of England.38

    CHAPTER 12 ENGLAND UNDER HENRY THE SECOND PART THE FIRST Henry Plantagenet, when he was but [only] t ...

  4. day13 cookie与session和中间件

    day13 cookie与session和中间件 今日内容概要 cookie与session简介 django操作cookie与session django中间件简介 如何自定义中间件 csrf跨站请 ...

  5. python 从ubantu环境迁移到windows环境

    下载安装Anaconda3 Anaconda3-2021.05-Windows-x86_64.exe 默认安装目录 C:\ProgramData\Anaconda3 可以启动Anaconda查看不同的 ...

  6. oracle 外部表查alter日志

    --创建文件夹,路径是alter日志的路径 create or replace directory data_dir as '/u01/app/oracle/diag/rdbms/orcl/orcl/ ...

  7. android:为TextView添加样式、跑马灯、TextSwitcher和ImageSwitcher实现平滑过渡

    一.样式 设置下划线: textView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线 textView.getPaint().setAnt ...

  8. oracle体系结构(图)

  9. Centos7源码部署Redis3.2.9

    目录 一.环境准备 二.安装 三.测试 四.编写启动脚本 一.环境准备 [Redis-Server] 主机名 = host-1 系统 = centos-7.3 地址 = 1.1.1.1 软件 = re ...

  10. Mysql配置 主从同步

    目录 一.准备 二.操作 主数据库操作 从服务器操作 一.准备 1.主从数据库版本最好一致 2.主从数据库内数据保持一致,若不一致,可将从库中所有数据删除,并将主库全部数据导入进去 主数据库:182. ...