丹东市网站建设_网站建设公司_Photoshop_seo优化
2026/1/11 18:24:03 网站建设 项目流程

2025年北京理工大学计算机考研复试机试真题

2025年北京理工大学计算机考研复试上机真题

历年北京理工大学计算机考研复试上机真题

历年北京理工大学计算机考研复试机试真题

更多学校完整题目开源地址:https://gitcode.com/u014339447/pgcode

百度一下pgcdoe即可查看,输入 “学校名称” 即可筛选该校历年机试真题,包括真题、ac代码、解题思路、视频讲解。

字符大小写交替-北京理工大学

题目描述

给你个字符,需要你输出从大写字母A AA开始到这个字符,然后又回到起点A AA的过程,其中交替大小写。

比如给你一个d dd,输出AbCdCbA

给你一个c cc,输出AbCbA

输入描述

一个英文字母。

输出描述

结果字符串。

输入样例
d
输出样例
AbCdCbA
#include<iostream>usingnamespacestd;intmain(){charc;cin>>c;//if (c=='A') cout<<"A"<<endl;//cout<<int('A')<<' '<<int('a')<<endl;intbase='a';intbase_c=c;//cout<<base_c<<base;if(base_c<base)c=c+('a'-'A');//cout<<c;inti=c-'a';//cout<<i;for(intj=0;j<=i;j++){if(j%2==0){charb=j+'A';cout<<b;}else{charb='a'+j;cout<<b;}}intType=(i%2);for(intj=1;j<=i;j++){if(j%2==Type){charb=c-j+'A'-'a';cout<<b;}else{charb=c-j;cout<<b;}}cout<<endl;}

确定二叉树的结构-北京理工大学

题目描述

给你一颗二叉树的先序 先序先序中序遍历 中序遍历中序遍历,请你输出这颗二叉树的后序遍历 后序遍历后序遍历

输入描述

两个字符串,其长度n nn均小于等于26 2626

第一行为先序遍历 先序遍历先序遍历,第二行为中序遍历 中序遍历中序遍历

输出描述

输入样例可能有多组,对于每组测试样例,输出一行,为后序遍历 后序遍历后序遍历的字符串。

输入样例
abc bac fdxeag xdefag
输出样例
bca xedgaf
#include<iostream>#include<string>usingnamespacestd;typedefstructLnode{chardata;structLnode*left;structLnode*right;}Lnode;voidstring2lnode(string l1,string l2,Lnode*&h){if(l2.size()<=0|l1.size()<=0){h=nullptr;return;}//cout<<l2[0]<<endl;h=newLnode;h->data=l1[0];//cout<<"l2 "<<l2<<endl;//cout<<"l1 "<<l1<<endl;intlen=l2.find(l1[0]);//cout<<"111 "<<l1.substr(0,len)<<" "<< l2.substr(1,len)<<endl;//cout<<"222 "<<l1.substr(len+1,l1.size()-len-1)<<" "<< l2.substr(len+1,l2.size()-len-1)<<endl;string2lnode(l1.substr(1,len),l2.substr(0,len),h->left);string2lnode(l1.substr(len+1,l1.size()-len-1),l2.substr(len+1,l2.size()-len-1),h->right);}voidpreorder(Lnode*&h){if(h!=nullptr){preorder(h->left);preorder(h->right);cout<<h->data;}}intmain(){string l1;string l2;while(true){getline(cin,l1);if(l1=="\0")break;//cout<<l1<<endl;getline(cin,l2);//cout<<l2<<endl;Lnode*h;string2lnode(l1,l2,h);preorder(h);cout<<endl;}}

表达式求值-北京理工大学

题目描述

读入一个只包含+ ++,− -,∗ *,/ //的非负整数计算表达式,计算该表达式的值。

如果该表达式格式有误,请输出N O NONO

输入描述

测试输入包含若干测试用例,每个测试用例占一行。

每行不超过200 200200个字符,整数和运算符之间用一个空格分隔。

没有非法表达式:不会出现/ //0 00这种情况。

当一行中只有0 00时输入结束,相应的结果不要输出。

输出描述

对每个测试用例输出1 11行,即该表达式的值,精确到小数点后2 22位。

输入样例
1 + 2 4 + 2 * 5 - 7 / 11 2 + 3 / / 6 0
输出样例
3.00 13.36 NO
#include<iostream>#include<string>#include<stack>#include<stdio.h>usingnamespacestd;intisd(chara){if((a<='9')&(a>='0'))return1;if((a=='+')|(a=='-')|(a=='*')|(a=='/'))return2;return3;}floatstr2n(string a){floataa=0;for(inti=0;i<a.size();i++){aa=aa*10+a[i]-'0';}returnaa;}intmain(){string a;while(1){stack<float>sa;stack<char>sb;getline(cin,a);if(a=="0")break;string b="";inttype=0;intcheck=0;floatfa=0;floatfb=0;intdoit=0;for(inti=0;i<=a.size();i++){if(a[i]==' '|i==a.size()){if(type==1){//cout<<"doit"<<doit<<endl;if(doit==1){fa=sa.top();sa.pop();fb=str2n(b);sa.push(fa*fb);doit=0;}elseif(doit==2){fa=sa.top();sa.pop();fb=str2n(b);sa.push(fa/fb);doit=0;}elsesa.push(str2n(b));//cout<<sa.top()<<endl;}if(type==2){if(b=="*"){doit=1;}elseif(b=="/"){doit=2;}elsesb.push(a[i-1]);}//cout<<b<<endl;b="";check=0;}else{b+=a[i];if(check==0){intt2=isd(a[i]);if(type==0){if(t2==1){type=t2;check=1;continue;}type=-1;break;}else{if(type!=t2&t2!=3){type=t2;check=1;continue;}type=-1;break;}}}//cout<<b<<endl;}if(type!=1){cout<<"NO"<<endl;continue;}// while(!sa.empty()){// cout<<sa.top()<<endl;// sa.pop();// }while(!sb.empty()){fa=sa.top();sa.pop();fb=sa.top();sa.pop();charc=sb.top();sb.pop();if(c=='+')sa.push(fb+fa);elsesa.push(fb-fa);}printf("%.2f\n",sa.top());// while(!sa.empty()){// cout<<sa.top()<<endl;// sa.pop();// }//cout<<"Yes"<<endl;}}

等腰梯形-北京理工大学

题目描述

输入高度 $ h $。

输入一个高为 $ h $,上底边长为 $ h $ 的等腰梯形。

例如 $ h = 4 $,图形如下:

**** ****** ******** **********
输入描述

一个整数:$ h $ 的值。

输入样例
4
输出样例
**** ****** ******** **********
#include<iostream>usingnamespacestd;intmain(){inta;cin>>a;intl=a+(a-1)*2;for(intjj=a;jj>0;jj--){intk=jj-1;for(intj=k;j>0;j--)cout<<" ";//cout<<k;for(intj=l-k-k;j>0;j--)cout<<'*';for(intj=k;k>0;k--)cout<<" ";cout<<endl;}}

```cpp # include<iostream> using namespace std; int main(){ int a; cin>>a; int l=a+(a-1)*2; for(int jj=a;jj>0;jj--){ int k=jj-1; for(int j=k;j>0;j--) cout<<" "; //cout<<k; for(int j=l-k-k;j>0;j--) cout<<'*'; for(int j=k;k>0;k--) cout<<" "; cout<<endl; } }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询