B
来源:互联网 发布:网络层次结构 编辑:程序博客网 时间:2024/04/30 12:44
第二次比赛,我感受到了我心态的问题,还有思维的缺陷把。 容易钻进死胡同。 这道题题意很简单,就是要去找符合条件的字符串。
/*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就是个彩笔,大彩笔,还不努力
阅读全文
0 0
- b
- b
- b
- //b
- B
- b
- B
- B
- B
- B
- b
- B
- B
- B
- B
- B
- B
- b
- MATLAB第三课--BP神经网络
- pandas or sql计算前后两行数据间的增值
- 在void方法中使用return
- 最新 21 款Android 自定义View及炫酷动画开源框架,总有一款适合你!
- Shell编写进度条
- B
- JDBC概述(持久化/版本的介绍)
- HDU 4135 Co-prime(容斥原理)
- windows下保存git用户名和密码
- Dom模型之dataset属性/Html元素标签的data-*属性
- 关于安卓 模块内的manifest文件使用占位符的思考
- CodeForces 287 D.Shifting(机智)
- fedora重新build rpm软件安装包
- 刚哥遇到了感情问题