2013年北理复试上机题

历年北京理工大学复试上机题题目汇总:

http://blog.csdn.net/u014552756/article/details/78505845


#include 
using namespace std;

int gcd(int a,int b)
{
    int t;
    if(a>a>>b)
    {
        cout<
2013年北理复试上机题_第1张图片

http://blog.csdn.net/axuan_k/article/details/45844255

#include 
#include 
#include   
using namespace std;  
struct node  
{  
    string a,b;  
};  
bool cmp(node x,node y)  
{  
    return x.a>tt)  
    {  
            ns[n++].a=tt;  
    }  
    for(i=0; i='A'&&ns[i].a[j]<='Z')  
                ns[i].a[j]+='a'-'A';  
        }  
    }  
    sort(ns,ns+n,cmp);  
    for(i=0; i

#include 
#include 
#include 
using namespace std;

int isEqual(string s1,string s2)
{
    char a[20],b[20];
    for(int i=0; i0)
        return 1;
    else
        return -1;
}

int main()
{
    string str[105],s;
    int n=0;
    while(cin>>s)
    {
        if(s=="0")
            break;
        else
            str[n++]=s;
    }
    //冒泡
    for(int i=n-1; i>0; i--)
        for(int j=0; j0)
            {
                s=str[j];
                str[j]=str[j+1];
                str[j+1]=s;
            }
        }
        
    for(int i=0; i

2013年北理复试上机题_第2张图片

#include
#include
using namespace std;

//根据中缀表达式求出后缀表达式
typedef struct node
{
    string v;
    node *l;
    node *r;
};

void dfs(node* T)
{
    if(T==NULL)
        return;
    cout<v;
    dfs(T->l);
    dfs(T->r);
}

void In2T(string In,node *&T)
{
    if(T==NULL)
    {
        T=new node;
        T->l=T->r=NULL;
    }
    int op=9999999,idx=-1,ex=0;   //a+(b+c)*d+e
    for(int i=In.length()-1; i>=0; i--) //找出优先级最低的运算符的位置,优先级越低深度越低
    {
        if(In[i]==')')
            ex+=2;
        else if(In[i]=='(')
            ex-=2;
        else if(In[i]=='+'||In[i]=='-')
        {
            if(ex+1=0; --idx2)
            if(In[idx2]!=')')
                break;
        T->v=In.substr(idx1,idx2-idx1+1);
        return ;
    }
    T->v=In[idx];
    In2T(In.substr(0,idx),T->l);
    In2T(In.substr(idx+1,In.length()-idx),T->r);
}

int main()
{
    string In;
    node *root=NULL;
    getline(cin,In);
    In2T(In,root);
    dfs(root);
    cout<

你可能感兴趣的:(北理考研初试复试,北京理工大学计算机考研)