HDU 1708 Fibonacci String (Fibonacci string)

Source: Internet
Author: User

Fibonacci StringTime limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5358 Accepted Submission (s): 1819

problem DescriptionAfter little Jim learned Fibonacci number in the class, he is very interest in it.
Now he's thinking about a new thing--Fibonacci String.

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

He's so crazying if someone gives him, strings str[0] and str[1], he'll calculate the str[2],str[3],str[4], St R[5] ....

For example:
If str[0] = "AB"; STR[1] = "BC";
He'll get the result, str[2]= "ABBC", str[3]= "BCABBC", str[4]= "ABBCBCABBC" ...;

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

The problem easier, you can assume the result would in the range of int.
 Sample Input
1AB BC 3

Sample Output
a:1b:3c:2d:0e:0f:0g:0h:0i:0j:0k:0l:0m:0n:0o:0p:0q:0r:0s:0t:0u:0v:0w:0x:0y:0z:0
 
AuthorLinle
SourceHDU 2007-spring Programming Contest
Puzzle : Find the letter of your n Fibonacci string ..... The nth Fibonacci string is calculated again.
AC Code:
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring > #include <string> #include <cstdlib> #include <iomanip> #include <algorithm> #include < Time.h>typedef Long long ll;using namespace Std;int main () {int t;    String S0,s1;int N; LL s[50]={0};s[1]=1;for (int i=2;i<50;i++) {s[i]=s[i-1]+s[i-2];} Cin>>t;while (t--) {cin>>s0>>s1>>n; LL ch1[26]={0}; LL ch2[26]={0};for (int i=0;i<s0.size (); i++) {ch1[s0[i]-' a ']++;    The character is converted into a digital}for (int i=0;i<s1.size (); i++) {ch2[s1[i]-' a ']++;   Characters converted to digital}if (n==0) {for (int i=0;i<26;i++) {cout<< (char) (' a ' +i) << ': ' <<ch1[i]<<endl;   N=0, only the first}cout<<endl; is output Continue;} for (int i=0;i<26;i++) {cout<< (char) (' a ' +i) << ': ' <<s[n-1]*ch1[i]+s[n]*ch2[i]<<endl; Accumulate to n-1 and Nth}cout<<endl;}    return 0;}


 

HDU 1708 Fibonacci String (Fibonacci string)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.