携程笔试题第二

#include <iostream>
#include <vector>
#include <numeric>
#include <limits>

using namespace std;

//携程笔试题
/*请完成下面这个函数,实现题目要求的功能
当然,你也可以不按照下面这个模板来作答,完全按照自己的想法来 ^-^
******************************开始写代码******************************/
//流水线,已经排列好了顺序,所以不需要再进行排序
int calcMinStaff(vector<string> str,int m){
    int res=m,start=0,end=0,savedata;
    for (int i = 0; i < m; ++i) {
        string te= str[i];
        int len=te.size();
        string a,b;
        int pos=te.find(',');
        a=te.substr(0,pos);
        b=te.substr(pos+1,len-pos);
        start=stoi(a);
        end=stoi(b);
        if(i==0){
            savedata=end;
        }
        else if(savedata<=start&&i>0){
            savedata=end;
            res--;
        }

    }
    return res;
}

//
int main() {
    int m;
    cin>>m;
    vector<string> str;//输入
    for (int i = 0; i <m; ++i) {
        string k;
        cin>>k;
        str.push_back(k);
    }
    int res = calcMinStaff(str,m);
    cout << res << endl;
    return 0;

}

#研发笔试##携程##笔试题目#
全部评论
携程今年也是前面有 20 道选择题吗?
点赞 回复
分享
发布于 2020-05-06 18:36

相关推荐

1 1 评论
分享
牛客网
牛客企业服务