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

1, input student information, names of scores (the number of results is not necessarily) the output of each student's school number and grade point average, and the number of courses over two failing students by failing several courses sorted in descending output.
input:
stu1
60 70 80 30
stu2
10 20 30 40 50
stu3
10 20 30 40 50 60 30
stu4
60 80 100
stu5
50 40 30 60 70
#
output:
stu1 60
stu2 30
stu3 34.2857
stu4 80
stu5 50
Failed several courses over two students are:
stu3 34.2857
stu2 30
stu5 50
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct student
{
    string name;
    vector<int> grade;
    int lownum = 0;
    double avgs;
};

bool cmp(student s1, student s2) {
    return s1.lownum > s2.lownum;
}

int main() {
    vector<student> v, vv;
    string s;
    cout << "Please enter student information: Name, enter # end result ...... " << endl;
     the while (cin >> S) {
         IF (S == " # " ) BREAK ; 
        Student STU; 
        stu.name = S;
         int Score, SUM = 0 , CNT = 0 ;
         the while (CIN >> Score) { 
            stu.grade.push_back (Score); 
            IF (Score < 60 ) stu.lownum ++ ; 
            SUM + = Score; 
            CNT ++ ;
             IF(getchar() == '\n') break;
        }
        stu.avgs = sum / (double)cnt;
        v.push_back(stu);
        if(stu.lownum > 2) vv.push_back(stu);
    }
    sort(vv.begin(), vv.end(), cmp);
    for(int i = 0; i < v.size(); i++) {
        cout << v[i].name << " " << v[i].avgs << endl;
    }
    cout << "不及格课程数超过2的学生有:" << endl;
    for(int i = 0; i < vv.size(); i++) {
        cout << vv[i].name << " " << vv[i].avgs << endl;
    }
    return 0;
}
2, the input string, the string comprises a digital output
input: 2.3ABC0-2.3
output:2.3 0 -2.3。
input: +004.500
output:4.5
(Originally output +4.5, but I feel that we should not need to '+', specific issues and problems right)
#include <iostream>
#include <vector>
using namespace std;

int main() {
    string s;
    while(cin >> s) {
        string str;
        vector<string> v;
        int dot;
        for(int i = 0; i < s.length(); i++) {
            if (s[i] == '+') continue;
            if (!isalpha(s[i])) str += s[i];
            if (isalpha(s[i]) || i == s.length() - 1 || s[i + 1] == '-') {
                if (str != "") {
                    if(str.length() != 1) {
                        int num = 0, num1, flag = 0, num2;
                        for(int j = 0; j < str.length(); j++) {
                            if(str[j] == '0') num++;
                            if(str[j] != '0' && !flag) {
                                flag++;
                                num1 = num;
                            }
                        }
                        num = 0;flag = 0;
                        for(int j = str.length() - 1; j >= 0; j--) {
                            if(str[j] == '0') num++;
                            if(str[j] != '0' && !flag) {
                                flag++;
                                num2 = num;
                            }
                        }
                        str = str.substr(num1, str.length() - num2 - num1);
                    }
                    v.push_back(str);
                    str = "";
                }
            }
        }
        for(int i = 0; i < v.size(); i++) {
            cout << v[i];
            if(i < v.size() - 1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

PS: The second question seems not perfect, and then taking the time to change it!

There are summer camps behind security research topics are also online, there is more time

Guess you like

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