您的位置:首页 > 其它

HDU 1708 Fibonacci String

2012-05-25 03:52 176 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1708

不能直接用string加,最后的位数很多,会超内存。一定注意特殊处理k=0和k=1的情况。最后有空行

View Code

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int a[100],b[100],c[100];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int k;
string s1,s2;
cin >> s1 >> s2 >> k ;
map <char,int> M1;
map <char,int> M2;
map <char,int> M3;
if(k==0)
{
for(int i=0;i<s1.length();i++)
M1[s1[i]]++;
for(int i=97;i<123;i++)
printf("%c:%d\n",i,M1[i]);
}
else if(k==1)
{
for(int i=0;i<s2.length();i++)
M2[s2[i]]++;
for(int i=97;i<123;i++)
printf("%c:%d\n",i,M2[i]);
}
else
{
for(int i=0;i<s1.length();i++)
M1[s1[i]]++;
for(int i=0;i<s2.length();i++)
M2[s2[i]]++;
while(--k)
for(int i=97;i<123;i++)
{
M3[i]=M1[i]+M2[i];
M1[i]=M2[i];
M2[i]=M3[i];
}
for(int i=97;i<123;i++)
printf("%c:%d\n",i,M3[i]);
}
putchar('\n');
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: