zoukankan      html  css  js  c++  java
  • 杭电acm1708

    http://acm.hdu.edu.cn/showproblem.php?pid=1708

    题意就是把两个串当做初始串,像斐波那契数列那样连接起来,然后计算第N个串各个字母出现的次数,思路是运用斐波那契数列思想,计算得,当N为0时,是第一个串,1时就是第二个串,三个以上的,就是串1对应f[n-2],串2对应f[n-1],然后逐个叠加

    #include<stdio.h>
    int main()
    {
        int f[55],i,str1[200],str2[200],n,l;
        char s1[50],s2[50];
        f[0]=f[1]=1;
        for(i=2;i<=50;i++)
          f[i]=f[i-1]+f[i-2];
        scanf("%d",&n);
        while(n--)
        {
             for(i=60;i<150;i++)
               str1[i]=str2[i]=0;
             scanf("%s %s %d",s1,s2,&l);
             i=0;
             if(l==0)
             {
                while(s1[i])
                  str1[s1[i++]]++;
             }
             else if(l==1)
               while(s2[i])
                 str2[s2[i++]]++;
             else 
             {
                while(s1[i])
                  str1[s1[i++]]+=f[l-2];
                i=0;
                while(s2[i])
                  str2[s2[i++]]+=f[l-1];
             }
             for(i='a';i<='z';i++)
                printf("%c:%d\n",i,str1[i]+str2[i]);
             printf("\n");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    List sort()方法
    解析器
    beautifulsoup库
    break 语句
    enumerate函数
    POJ 1915 Knight Moves
    POJ 1745 Divisibility
    POJ 1731 Orders
    POJ 1664 放苹果
    POJ 1606 Jugs
  • 原文地址:https://www.cnblogs.com/huzhenbo113/p/3084970.html
Copyright © 2011-2022 走看看