NC205164. Figureoutthesequence
描述
The Coronavirus is evil and loves to store everything into its RNA, which is why it often has genetic mutation.
For the following turns, the virus will always add the sequence it got in the previous turn to the beginning of the current sequence.
As an expert in biochemistry, GGG has been devoting himself into analyzing this virus since its outbreak, whose task is to figure out the exact composition of this virus (That is: how many times does each letter appear in the final sequence). However, what he can get is only how many turns the virus has changed its RNA and the initial two sequences. can you help him to solve this problem?
输入描述
The input only consists of one test case.
The first line and the second line will be two string and , which are the initial RNA sequences, the sequences are both made up of lower-case Latin letters and upper-case Latin letters. The virus starts with string .
The third line will be an integer , which is the number of turns that the virus has taken to modify its RNA.
It's guaranteed that , the length of two strings .
输出描述
The output should contain several lines for each letters in the final RNA sequence in lexicographical order.
Each line should be in format like , the first letter is the related lower-case letter, the second one is a colon, the third one is a space and then is an integer which is the number of occurrences of this letter in the final RNA sequence.
If a letter doesn't appear in the sequence, you can simply ignore it.
示例1
输入:
Abc def 4
输出:
A: 1 b: 1 c: 1 d: 2 e: 2 f: 2
C++ 解法, 执行用时: 6ms, 内存消耗: 508K, 提交时间: 2022-05-02 20:01:36
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[45][200]; string s1, s2; int main() { ll n; cin >> s1 >> s2 >> n; for (auto x : s1) a[1][x]++; for (auto x : s2) a[2][x]++; for (ll i = 3; i <= n; i++) for (ll j = 'A'; j <= 'z'; j++) a[i][j] = a[i - 1][j] + a[i - 2][j]; for (ll i = 'A'; i <= 'z'; i++) if (a[n][i]) printf("%c: %d\n", i, a[n][i]); return 0; }