欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

2010年北京大学计算机研究生机试真题

发布时间:2024/7/19 编程问答 87 豆豆
生活随笔 收集整理的这篇文章主要介绍了 2010年北京大学计算机研究生机试真题 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

http://ac.jobdu.com/problem.php?pid=1149   子串计算

#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++;}elsemymap.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)) //判断最高位是否为1a = (a<<1)+1;elsea = 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");elseprintf("NO\n");}return 0; }



 

总结

以上是生活随笔为你收集整理的2010年北京大学计算机研究生机试真题的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。