• Codeforces 260B


    260B - Ancient Prophesy

    思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部分。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+5;
    map<string,int>mp;
    string s;
    int d[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    bool isOK(string s)
    {
        if(s[2]!='-'||s[5]!='-')return false;
        if(s[0]=='-'||s[1]=='-'||s[3]=='-'||s[4]=='-')return false;
        int a=(s[0]-'0')*10+s[1]-'0';
        int b=(s[3]-'0')*10+s[4]-'0';
        if(b<=0||b>12)return false;
        if(a<=0||a>d[b-1])return false;
        return true;
    }
    int main()
    {
        cin>>s;
        int cnt=0;
        string ans;
        for(int i=6;i<s.size()-3;i++)
        {
            if(s[i]=='2'&&s[i+1]=='0'&&s[i+2]=='1'&&'3'<=s[i+3]&&s[i+3]<='5')
            {
                string s1=s.substr(i-6,6);
                if(isOK(s1))
                {
                    string s2=s.substr(i-6,10);
                    mp[s2]++;
                    if(mp[s2]>cnt)
                    {
                        cnt=mp[s2];
                        ans=s2;
                    }
                }
            }
        }
        cout<<ans<<endl;
        return 0; 
    } 
  • 相关阅读:
    第一个Struts1步骤
    struts框架学习过程中的问题
    struts2笔记
    搭建struts2框架
    一个系统钩子
    TMemIniFile 与TIniFile 区别
    rc4加密
    注册dll
    delphi 功能函数大全-备份用
    VC中文件路径问题
  • 原文地址:https://www.cnblogs.com/widsom/p/7205556.html
Copyright © 2020-2023  润新知