360笔试 0911 , AC1.82,求大佬第一题解法

第一题,企业管理 , AC 0.82
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n , m;
    cin >> n >> m;

    unordered_map<int , int> index_1;
    unordered_map<int , int> index_0;
    set<int> se_1;
    set<int> se_0;
    int first_index_1 = -1 , first_index_0 = -1;
    for(int i = 0 ; i < m ; ++i)
    {
        int ai , bi;
        cin >> ai >> bi;
        if(bi == 1)
        {
            first_index_1 = i;
            se_1.insert(ai);
            index_1[ai] = i;
        }
        else
        {
            if(first_index_0 == -1)
                first_index_0 = i;
            index_0[ai] = i;
            se_0.insert(ai);
        }    
    }
    vector<int> res;
    for(int i = 1 ; i <= n ; ++i)
    {
        if(se_0.count(i) && se_1.count(i) && index_1[i] == 0 && index_0[i] == m-1 )
            res.push_back(i);
        if(!se_0.count(i) && !se_1.count(i))    // 没有打卡记录的情况
            res.push_back(i);

        if(se_1.count(i) && !se_0.count(i) && index_1[i] == 0 && first_index_0-index_1[i]  >= n - se_0.size() )
            res.push_back(i);
        if(!se_1.count(i) && se_0.count(i) && index_0[i] == m-1 && index_0[i]-first_index_1 >= n - se_1.size() )
            res.push_back(i);
    }
    sort(res.begin() , res.end());
    for(int i = 0 ; i < res.size() ; ++i )
    {
        cout << res[i] << " ";
    }
    return 0;
}
第二题,验证密码
#include<bits/stdc++.h>
using namespace std;

bool check(string str)
{
    int n = str.size();
    if(n < 8)
        return false;
    int count_I = 0 , count_char = 0 , count_CHAR = 0 , count_Tar = 0;
    for(int i = 0 ; i < n ; ++i)
    {
        if(count_I && count_char && count_CHAR && count_Tar)
            return true;
        else
        {
            if(isdigit(str[i]))
                count_I++;
            else if(isalpha(str[i]))
            {
                if(str[i] > 'Z')
                    count_char++;
                else
                    count_CHAR++;
            }
            else
                count_Tar++;
        }
        
    }
    if(count_I && count_char && count_CHAR && count_Tar)
        return true;
    else
        return false;
}

int main()
{
    string str;
    while (cin >> str)
    {
        if( check(str) )
            cout << "Ok" << endl;
        else
            cout << "Irregular password" << endl;
    }
    
    return 0;
}


#笔试题目##360公司#
全部评论
第一题 我定义了3个规则.. 1. 片段中在第一个人上班之后的人上班, 这些人都不可能是 2. 片段中最后一个人下班之前下班的人, 这些人都不可能是 3. 片段中如果某一个人下班,且他没有上班记录,那么片段中第一个上班的人不可能是 无证明...过程. 有大佬可以证明一下 AC
2 回复
分享
发布于 2020-09-12 09:33
第一题,大佬来看一下
点赞 回复
分享
发布于 2020-09-11 22:23
阿里巴巴
校招火热招聘中
官网直投
企业管理直接做不到 我太菜了
点赞 回复
分享
发布于 2020-09-11 22:53
第一题把请假的都输出了就到82了。。。
点赞 回复
分享
发布于 2020-09-11 22:58
#360 第二题企业:思想 我认为可以分为三种情况: 1 只有上班打卡记录; 2 只有下班打卡记录; 3 有上下班打卡记录 第一种:老板可能是序列中的第一个和序列之外的数 第二种:老板可能是序列的最后一个和序列之外的数 第三种:首先序列之外的可能是老板。首尾两个数判断比较复杂,第一个数是老板需要满足条件:下班打卡工号集合需包含在上班打卡工号集合中,且第一个上班打卡工号的下班打卡记录不能出现在中间。 同理对最后一个数是老板的情况进行判断。
点赞 回复
分享
发布于 2020-09-12 11:28
都处理成中间片段,因为老板一定是第一个打卡上班和最后一个打卡下班,所以中间片段记录的都是员工,若某位员工既没有上班记录也没有下班记录,则可能是老板。
点赞 回复
分享
发布于 2020-09-12 14:20
楼主收到面试了吗
点赞 回复
分享
发布于 2020-09-15 02:25
记上班打卡的人集合为S,下班打卡的人集合为T。遍历所有员工i,有四种情况: 1. i既不在S,也不在T,符合要求 2. i只在S,则i必须是S的第一个,且T包含于S(否则说明有个员工在老板上班之前打卡) 3. i只在T,则i必须是T的最后一个,且S包含于T(否则说明有个员工在老板下班之后打卡) 4. i在S和T,则i为两端,且S=T
点赞 回复
分享
发布于 2020-09-17 11:22

相关推荐

2 收藏 评论
分享
牛客网
牛客企业服务