第一题,企业管理 , 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; }
全部评论
(8) 回帖