PAT (Advanced Level) 1071. Speech Patterns (25)

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT (Advanced Level) 1071. Speech Patterns (25)相关的知识,希望对你有一定的参考价值。

简单题。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

char s[1048576+10];
string ans[1048576+10];
int tot;

bool g(char c)
{
    if(c>=a&&c<=z) return 1;
    if(c>=0&&c<=9) return 1;
    if(c>=A&&c<=Z) return 1;
    return 0;
}

int main()
{
    gets(s);
    for(int i=0;s[i];i++)
        if(s[i]>=A&&s[i]<=Z) s[i]=s[i]-A+a;
    string f=""; tot=0;
    for(int i=0;s[i];i++)
    {
        if(g(s[i])) f=f+s[i];
        else
        {
            if(f=="") continue;
            ans[tot++]=f;
            f="";
        }
    }
    if(f!="") ans[tot++]=f;
    sort(ans,ans+tot);
    int now=0,pre=0;
    string out;
    int num=0;

    while(1)
    {
        if(ans[now]==ans[pre]) now++;
        else
        {
            if(now-pre>num)
            {
                num=now-pre;
                out=ans[pre];
            }
            pre=now;
        }
        if(pre==tot) break;
    }

    cout<<out<<" "<<num<<endl;
    return 0;
}

 

以上是关于PAT (Advanced Level) 1071. Speech Patterns (25)的主要内容,如果未能解决你的问题,请参考以下文章

PAT (Advanced Level) 1025. PAT Ranking (25)

PAT Advanced Level 1044

PAT Advanced Level 1043

PAT Advanced Level 1079

PAT Advanced Level 1095

PAT Advanced Level 1038