• HDU4847,kmp模板题



    Chen, Adrian (November 7, 2013). “Doge Is An Ac- tually Good Internet Meme. Wow.”. Gawker. Retrieved November 22, 2013.

    Doge is an Internet meme that became popular in 2013. The meme typically con- sists of a picture of a Shiba Inu dog ac- companied by multicolored text in Comic Sans MS font in the foreground. The text, representing a kind of internal monologue, is deliberately written in broken English, and usually contains the word “wow” and the phrases “such x”, “much x”, “many x”, “very x” and “so x”.
    Kabosu, the Shiba Inu featured in the original meme, was first pictured in a 2010 blog post by Atsuko Sato, a Japanese kindergarten teacher. Afterwards, varia- tions of the pictures using overlaid Comic Sans text were posted from a Tumblr blog, Shiba Confessions. However, the use of the intentionally misspelled “doge” dates back to June 2005, when it was mentioned in an episode of Homestar Runners puppet series.
    In August 2013, images of the meme were spammed on Reddit’s r/MURICA subreddit by 4chan’s random imageboard, /b/. A search of the term doge on Google Trends shows an explosion of popularity occurring in October 2013, and more so in the following month. By November 2013, the meme had become widespread on the Internet. Google later created a Doge Easter egg: when doge meme was entered into the YouTube search bar, all of the site’s text would be displayed in colorful Comic Sans, similar to the kind used by the meme.
    The meme was ranked #12 on MTV’s list of “50 Things Pop Culture Had Us Giving Thanks For” in 2013. Io9 compared the internal dialog of the Shiba Inu dogs to lolcat-speak. The image most commonly associated with the meme is of a female Shiba Inu named Kabosu, taken from a Japanese blog documenting the dog’s daily activities. The spelling of doge has several variants, leading to debate on its actual pronunciation. On December 13, Doge was named the “top meme” of 2013 by Know Your Meme.
    In December 2013, the Dogecoin was introduced as a new cryptocurrency, making it the first cryptocurrency to be based on an Internet meme; the viral phenomenon, along with usage of the Comic Sans MS typeface, gave it “the Internet density of a large star” according to Medium writer Quinn Norton.
    In late December 2013, members of the U.S. Congress produced material in the meme’s style. Huffington Post commented that Doge was “killed” because of the Congress members’ usage of the meme.
    By early 2014, Doge’s popularity was sustained by internet communities on social media, accompanied by the rapid growth and acceptance of Dogecoin. In April 2014, Doge experienced a second major media resurgence due to revelations of the Dogecoin community’s intent to sponsor Josh Wise in NASCAR and place a picture of the Shiba Inu on his vehicle.

    —— Doge (meme). (2014, May 18).
    In Wikipedia, The Free Encyclopedia. Retrieved 02:00, May 22, 2014, from
    http://en.wikipedia.org/w/index.php?title=Doge_(meme)&oldid=609040691

    Now, Doge wants to know how many words “doge” are there in a given article. Would you like to help Doge solve this problem?

    Input

    An article that Doge wants to know.
    The size of the article does not exceed 64KB. The article contains only ASCII characters.

    Output

    Please output the number of word “doge” (case-insensitive). Refer to the samples for more details.

    Sample Input

    
     

    adoge

    cutedo

    yourge

    blownDoge

    lovelyDooge

    Wow! Such Dooooooooooooooge!!!

    D0ge

    dOge

    DOGE

    dogedoge

    Sample Output

    
     

    6

    题意:

    在给定的文本中找到doge出现的次数=.=

    思路:

    将字符串全部转换为小写或大写,KMP一一进行查询,稍微注意输入方式就行了.不过题目数据有点水,直接暴力也能过.

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    int next1[10000];
    string s;
    string p="doge";
    void convert(string &str)//将所有字符转小写
    {
        int len=str.length();
        for(int i=0;i<len;i++)
            str[i]=tolower(str[i]);
    }
    void getnext()//得到next数组
    {
        memset(next1,0,sizeof(next1));
        int n=s.length();
        int i=0;
        int j=-1;
        next1[0]=-1;
        while(i!=n)
            {
                if(j==-1||s[i]==s[j])
                    {
                        if(s[i+1]==s[j+1])
                            next1[++i]=next1[++j];//失配直接跳过,优化
                        else
                            next1[++i]=++j;
                    }
                else
                    j=next1[j];
            }
    }
    
    int kmp()
    {
        int i=0,j=0,sum=0;
        int n=s.length(),m=p.length();
        getnext();
        while(i<n&&j<m)
            {
                if(j==-1||s[i]==p[j])
                    i++,j++;
                else
                    j=next1[j];
                if(j==m)
                    {
                        sum++;
                        j=0;
                    }
            }
        return sum;
    }
    
    int main()
    {
        int cnt=0;
        while(getline(cin,s))
            {
                convert(s);
                cnt+=kmp();
            }
        printf("%d
    ",cnt);
    }
    
  • 相关阅读:
    开放平台整理
    Ubuntu Linux之软件源 解释
    遇到的几个linux问题,顺便把网上查到的帖过来
    Linux之网络配置
    Linux维护之Grub应用与问题汇总
    Linux维护之我用过的命令汇总(没多少意义,给我自己看的)
    大数据hadoop目录
    大数据hadoop环境搭建伪分布式模式
    大数据数据分析numpy库数组创建方式、数组的数据类型
    大数据hadoop运行模式
  • 原文地址:https://www.cnblogs.com/BlueDoor1999/p/13301391.html
Copyright © 2020-2023  润新知