2010年北京大学计算机研究生机试真题
2012-02-24 17:03
344 查看
http://ac.jobdu.com/problem.php?pid=1149 子串计算
http://ac.jobdu.com/problem.php?pid=1151 位操作练习
#include<iostream> #include<cstdio> #include<map> #include<string> using namespace std; int main(void) { string t,str; map<string,int> mymap; map<string,int>::iterator iter,p; int i,j; while(cin>>t) { mymap.clear(); for(i=0;i<t.size();i++) { for(j=i;j<t.size();j++) { str = t.substr(i,j-i+1); //mymap[str]++; 这个方法也是可以的,下边操作同样可以向map中插入数据,就不需要使用下面的insert了(下面23--29行的代码可以省略了) p = mymap.find(str); if(p!=mymap.end()) { p->second++; } else mymap.insert(make_pair(str, 1)); } } for(iter=mymap.begin();iter!=mymap.end();iter++) { if(iter->second>1) cout<<iter->first<<" "<<iter->second<<endl; } } return 0; }
http://ac.jobdu.com/problem.php?pid=1151 位操作练习
#include<iostream> #include<cstdio> using namespace std; bool solve(unsigned short a,unsigned short b) { for(int i=1;i<=16;i++) { if(a >= (1<<15)) //判断最高位是否为1 a = (a<<1)+1; else a = a<<1; if(a == b) return true; } return false; } int main(void) { int n; unsigned short a,b; //题目要求是16位,所以要用unsigned short类型。 int类型是32位的,所以a和b不能够定义为int类型的 scanf("%d",&n); while(n--) { scanf("%hu %hu",&a,&b); //unsigned short 类型的输入格式问题 //cin>>a>>b; //cin来输入也是可以的 if(solve(a,b)) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- 题目1153:括号匹配问题(2010年北京大学计算机研究生机试真题,堆栈的使用)
- 2010年华中科技大学计算机研究生机试真题之六
- 九度题目1154:Jungle Roads Kruskal算法 2010年北京大学计算机研究生机试真题
- 2012年北京大学计算机研究生机试真题 -Is It A Tree?
- 题目1051:数字阶梯求和 2010年哈尔滨工业大学计算机研究生机试真题
- 2010年吉林大学计算机研究生机试真题九度online judge 1466排列与二进制
- 2010年浙江大学计算机及软件工程研究生机试真题之三
- 九度题目1003:A+B && 2010年浙江大学计算机及软件工程研究生机试真题
- 2010年华中科技大学计算机研究生机试真题之六
- 1041: A+B--2010年浙江大学计算机及软件工程研究生机试真题
- 九度 题目1112:拦截导弹 2007年北京大学计算机研究生机试真题 动态规划
- 题目1144:Freckles(2009年北京大学计算机研究生机试真题)
- 2010年浙江大学计算机及软件工程研究生机试真题
- 题目1112:拦截导弹(2007年北京大学计算机研究生机试真题:动态规划)
- 2010年上海交通大学计算机研究生机试真题
- 2010年浙江大学计算机及软件工程研究生机试真题(1)
- 2007年北京大学计算机研究生机试真题 二叉树
- 2010年哈尔滨工业大学计算机研究生机试真题
- 1006 ZOJ问题(2010年浙江大学计算机及软件工程研究生机试真题)
- 2011年北京大学计算机研究生机试真题(dijkstra+优先队列)