zoukankan      html  css  js  c++  java
  • 北京理工大学复试上机--2015

    1、图形输出:输入 0-9 内的奇数,输出用*组成的正方形中间掏出来一个空的菱形。
    我是按照这种输出的
    9
    *********
    **** ****
    ***   ***
    **     **
    *       *
    **     **
    ***   ***
    **** ****
    *********
    8
     
    #include <iostream>
    using namespace std;
    int main() {
        int n;
        while(cin >> n) {
            if(n == 0 || n %2 == 0) cout << endl;
            else {
                for(int i = 0; i < n / 2; i++) {
                    for(int j = 0; j < n; j++) {
                        if(j > n / 2 - i && j < n / 2 + i) cout << " ";
                        else cout << "*";
                    }
                    cout << endl;
                }
                for(int i = n / 2; i < n; i++) {
                    for(int j = 0; j < n; j++) {
                        if(j > i - n / 2 && j < n + n / 2 - i - 1) cout << " ";
                        else cout << "*";
                    }
                    cout << endl;
                }
            }
        }
        return 0;
    }
     
    2、有3个字母a,b,c:你输入一个数字,要输出所有的组合字符和组合数
    输入: 1    输出: a,b,c 3
    输入: 2    输出: aa,ab,ac,ba,bb,bc,ca,cb,cc 9
    #include<iostream>
    #include<vector>
    
    using namespace std;
    
    vector<string> perm(vector<string> a, vector<string> b) {
        vector<string> v;
        for(int i = 0; i < a.size(); i++) {
            for(int j = 0; j < b.size(); j++) {
                v.push_back(a[i] + b[j]);
            }
        }
        return v;
    }
    
    int main() {
        int n, i, j ,k;
        char ch[3] = {'a', 'b', 'c'};
        while (cin >> n) {
            vector<string> v, res;
            v = {"a", "b", "c"};
            res = v;
            for(i = 1; i < n; i++) {
                res = perm(res, v);
            }
            for(i = 0; i < res.size(); i++) {
                cout << res[i];
                if(i < res.size() - 1) cout << ",";
            }
            cout << " " << res.size() << endl;
        }
        return 0;
    }
     
    3、表达式展开,比如输入a-(b+c),输出a-b-c
    输入: a-(b-(((c+d))))
    输出: a-b+c+d
    #include <iostream>
    #include <vector>
    #include <stack>
    using namespace std;
    int main() {
        string s;
        while (cin >> s) {
            int i, l, j = 0;
            int st[100];
            stack<int> ss;
            l = s.length();
            for (i = 0; i < l; i++) {
                if (s[i] == '(') {
                    if (s[i - 1] == '-') st[j++] = 1;
                    else st[j++] = 0;
                    ss.push(i);
                }
                else if (s[i] == ')') {
                    if (st[--j] == 1) {
                        int k = ss.top();
                        while (k != i) {
                            if (s[k] == '-') s[k++] = '+';
                            else if (s[k] == '+') s[k++] = '-';
                            else k++;
                        }
                    }
                    ss.pop();
                }
                else continue;
            }
            for (i = 0; i < l; i++) {
                if (s[i] == '(' || s[i] == ')') continue;
                cout << s[i];
            }
            cout << endl;
        }
        return 0;
    }
    4、求字符串1与字符串2的最大公共子串的长度及此长度最大公共子串的个数。
    输入: abcdefg Eebcdfg  (最大公共子串:bcd)    
    输出: 3 1
    输入: abcdefg abcddefg  (最大公共子串为:abcd defg)
    输出: 4 2
    #include<iostream>
    #include<vector>
    #include<map>
    using namespace std;
    int main() {
        string a, b;
        while(cin >> a >> b) {
            int la = a.length();
            int lb = b.length();
            int maxn = 0, num = 0;
            map<int, vector<string> > mmp;
            string str;
            for(int i = 0; i < la; i++) {
                for(int j = 0; j < lb; j++) {
                    if(a[i] == b[j]) {
                        int pi = i, pj = j;
                        while(a[pi] == b[pj] && pj < lb && pi < la) {
                            num++;
                            str += a[pi];
                            pj++;
                            pi++;
                        }
                        if(num >= maxn) maxn = num;
                        mmp[num].push_back(str);
                        str = "";
                        num = 0;
                    }
                }
                
            }
            cout << maxn << " " << mmp[maxn].size() << endl;
    
        }
        return 0;
    }
  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/ache/p/12576237.html
Copyright © 2011-2022 走看看