B - Ancient Prophesy CodeForces - 260B

第二次比赛,我感受到了我心态的问题,还有思维的缺陷把。 容易钻进死胡同。 这道题题意很简单,就是要去找符合条件的字符串。

/*If I get TLE , it is good.If I get AC,it's NICE !*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <cmath>
#include <queue>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
const int INF=2147483647;
const int MAXN=1e7+10;
const ll mod=1e9+7;
using namespace std;
typedef long long ll;
map <string,int> temp;
char str[MAXN];
int is(char x)
{
    if(x>='0'&&x<='9')return 1;
    else return 0;
}
int main(void)
{
    temp.clear();
    scanf("%s",str+1);
    int len=strlen(str+1);
    for(int i=1; i<=len-9; i++)
    {
        if(  is(str[i]) &&is(str[i+1]) &&str[i+2]=='-' &&is(str[i+3]) && is(str[i+4])  && str[i+5]=='-' && is(str[i+6]) && is(str[i+7] )&&  is(str[i+8]) &&  is(str[i+9])  )
        {
            int nian=(str[i+9]-'0')*1+(str[i+8]-'0')*10+(str[i+7]-'0')*100+(str[i+6]-'0')*1000;
            int yue=(str[i+3]-'0')*10+str[i+4]-'0';
            int ri=(str[i]-'0')*10+str[i+1]-'0';
            if(yue==0 || ri==0) continue;
            if(yue==4 ||yue==6 ||yue==9 ||yue==11  )
            {
                if(ri==31)  continue;
            }
            if(nian<2013 || nian>2015)  continue;
            if(yue>12 || yue <1)  continue;
            if(yue==2)
            {
                if(ri>=29 || ri ==0)
                    continue;
            }
            string s;
            //s.resize(15);
            //s.clear();
            int k=i;
            for(int j=0;j<=9;j++)
            {
                //s[j]=str[k++];
                s += str[k++];
                //printf("??? %d\n",s.size());
            }
            //cout << s <<endl;
            //cout <<temp[s] << endl;
            ++temp[s];
            //cout <<temp[s] << endl;
        }
    }

    int maxx=-1;
    for(map<string,int>::iterator it= temp.begin();it!=temp.end();it++)
    {
        if(maxx < it->second) maxx = it->second ;
    }
    for(map<string,int>::iterator it= temp.begin();it!=temp.end();it++)
    {
        if(maxx == it->second) {(cout << it->first<<endl) ; return 0;}
    }
}

要注意的地方:
1.对于年份,注意闰年和平年对2月造成的影响;
2.对于月份,如果大于12,或者小于1,continue;
3.对于日,分类在闰年和平年的情况下,如果是闰年,2月如果大于30 || 小于1 continue; 其他月份分30,和31天;平年同理

还有对map容器遍历的过程,今天还是和学长请教了,实在不想看博客,静不下心来的表现.(对MAP的遍历还要多敲几遍,熟悉套路)

for(map<string,int>::iterator it= temp.begin();it!=temp.end();it++)
    {
        if(maxx < it->second) maxx = it->second ;
    }
    for(map<string,int>::iterator it= temp.begin();it!=temp.end();it++)
    {
        if(maxx == it->second) {(cout << it->first<<endl) ; return 0;}
    }

这场比赛下来,我学到了什么
1.对于思维题,一定要活跃一点。
2.如果做不出来,可以先放一放,看下面的题,不要想着前面的题又做下面的题,不然一题都做不出来。

// 你TM就是个彩笔,大彩笔,还不努力

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务