The Beijing Institute of Technology re-examination machine --2012

1. Enter a ten positive integer numbers in ascending order
Input: 125,791,045,672,426
Output: 1,2,5,7,9,10,24,26,45,67
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int a, i;
    vector<int> v;
    for (i = 0; i < 10; i++)
    {
        scanf("%d", &a);
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    for (i = 0; i < 10; i++)
    {
        cout << v[i];
        if (i < 9)
            cout << ",";
    }
    return 0;
}
2, students (student number, name, sex, age), three students of the initialization information
(10, wes, f, 23) (20, ert, f, 45) (30, str, t, 89), and then to insert, and delete student information
In addition to processing
For example: I12, rt, f, 67 represent insertion 12, rt, f, 67
D10 means to delete student number 10 students of information
After each output operation is completed for all students to learn information sorted by descending number
Input: I12, rt, f, 67
Output: (30, str, t, 89), (20, erf, f, 45), (12, rt, f, 67), (10, wes, f, 23)
Input: D10
Output: (30, str, t, 89), (20, erf, f, 45), (12, rt, f, 67)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct student
{
    int age, id;
    string name, gender;
};

bool cmp(student t1, student t2)
{
    if (t1.id != t2.id)
        return t1.id > t2.id;
}

int main()
{
    int a, i, j;
    string s;
    student stu;
    vector<student> v;
    student st[3];
    st[0].id = 10; st[0].name = "wes"; st[0].gender = "f"; st[0].age = 23;
    st[1].id = 20; st[1].name = "erf"; st[1].gender = "f"; st[1].age = 45;
    st[2].id = 30; st[2].name = "str"; st[2].gender = "t"; st[2].age = 89;
    v.push_back(st[0]);
    v.push_back(st[1]);
    v.push_back(st[2]);
    while (getline(cin, s)) {
        string str[4];
        if (s[0] == 'I') {
            int n = (s[1] - '0') * 10 + (s[2] - '0');
            stu.id = n;
            n = s[s.length() - 1] - '0' + (s[s.length() - 2] - '0') * 10;
            stu.age = n;
            string ss = "";
            for (i = 4; i < s.length(); i++) {
                if (s[i] == ',') {
                    stu.name = ss;
                    ss = "";
                    break;
                }
                ss += s[i];
            }
            for (j = i + 1; j < s.length(); j++) {
                if (s[j] == ',') {
                    stu.gender = ss;
                    break;
                }
                ss += s[j];
            }
            v.push_back(stu);
            sort(v.begin(), v.end(), cmp);
            for (i = 0; i < v.size(); i++) {
                cout << "(" << v[i].id << "," << v[i].name << "," << v[i].gender << "," << v[i].age << ")";
                if (i < v.size() - 1)
                    cout << ",";
            }
        }
        if (s[0] == 'D') {
            int n = (s[1] - '0') * 10 + (s[2] - '0');
            for (i = 0; i < v.size(); i++) {
                if (v[i].id == n)
                {
                    v.erase(v.begin() + i);
                    break;
                }
            }
            sort(v.begin(), v.end(), cmp);
            for (i = 0; i < v.size(); i++) {
                cout << "(" << v[i].id << "," << v[i].name << "," << v[i].gender << "," << v[i].age << ")";
                if (i < v.size() - 1)
                    cout << ",";
            }
        }
    }

    return 0;
}
3, the preamble and the sequence is determined using the results preorder
Example:
(Press after the sequence, sequence): CHBEDA CBHADE
Output: ABCHDE
 
This title is currently not completely clear, first empty
 
 
PS: do not rush it to another title, very flustered! ! ! To ease a little, come on!

Guess you like

Origin www.cnblogs.com/ache/p/12571658.html