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;
}
时间: 2024-10-13 06:00:05

PAT (Advanced Level) 1071. Speech Patterns (25)的相关文章

PAT 1071. Speech Patterns (25)

1071. Speech Patterns (25) People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker's ident

PAT:1071. Speech Patterns (25) AC

#include<ctype.h> #include<iostream> #include<map> #include<string> using namespace std; bool check(char a) //判断是否为有效字符 { if(isdigit(a) || isalpha(a)) return true; return false; } int main() { map<string,int> count; //单词与次数的映

1071. Speech Patterns (25)

map的使用 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such

PAT (Advanced Level) 1083. List Grades (25)

简单排序. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std

PAT (Advanced Level) 1021. Deepest Root (25)

先并查集判断连通性,然后暴力每个点作为根节点判即可. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<vector> using namespace std; struct Edge { int a,b; }e[20000]; int n,sz

PAT (Advanced Level) 1020. Tree Traversals (25)

递归建树,然后BFS一下 #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<vector> using namespace std; const int maxn=40; int a[maxn],b[maxn]; int n,tot; struc

PAT (Advanced Level) 1114. Family Property (25)

简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; struct X { int id; int Father,Mother; int k;

PAT (Advanced Level) 1085. Perfect Sequence (25)

可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; int n; long long k; long l

PAT (Advanced Level) 1109. Group Photo (25)

简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<string> #include<algorithm> #include<iostream> using namespace std