zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Spring4
    Mysql索引优化、JMM内存模型
    深入浅出JVM
    ZGC垃圾搜集器
    Hibernate4基础
    红楼梦 各版本及资料
    JavaME环境配置
    5.1 Intent
    4.3 异步任务
    4.2.2 网络编程之Socket
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5634029.html
Copyright © 2011-2022 走看看