美团春招测开 - 第四场 3.29 笔试
美团
单选 :
考察了数据库,os,大模型,ds,计网的一些问题 :
- union和union all的区别,sql语句中like _ % 的使用 ,分解关联查询的优势
- 大根堆 ,快排时间复杂度.... ,森林节点数计算,hanoi问题 ;
- 一些大模型问题...
- ...
编程 :
第一道过75%,第23题a了 ;
字符串模拟题
不知道为什么只能过75% ;
#include<bits/stdc++.h>
using namespace std ;
#define endl '\n'
// 字符串模拟问题
bool pd1(string s) {
for (char c : s) {
if (c >= '0' && c <= '9') continue ;
else return false ;
}
return true ;
}
bool pd2(string s) {
if (pd1(s) == false) return false ;
if(s[0]>='1') return true ;
else return false ;
}
int main() {
int t ;
cin >> t ;
while (t--) {
string s ;
cin >> s ;
int n ;
cin >> n ;
int len = s.size() ;
if (len > 4 && s.substr(0, 4) == "TEMP" &&
n <= 120) cout << "Temporary" << endl ;
else if (len == 9 && s.substr(0, 3) == "VIP" &&
pd1(s.substr(3, 6))) cout << "VIP" << endl ;
else if (len == 7 && s.substr(0, 3) == "MER" &&
pd2(s.substr(3, 4))) cout << "Merchant" << endl ;
else if (len == 6 && s[0] >= 'A' && s[0] <= 'Z' &&
pd1(s.substr(1, 5))) cout << "Normal" << endl ;
else cout << "Invalid" << endl ;
}
}
调休问题 :
/ 调休问题// 健康 : 每一天工作时间不超过k// 保持总时长不变 ,是否可以调休达到健康
#include<bits/stdc++.h>
using namespace std ;
void fyj(){
int n , k ; cin >> n >> k ;
int sum = 0 , p = n * k ;
for(int i=0;i<n;i++){
int a ; cin >> a ;
sum += a ;
}
if(sum > p) cout << "NO" << endl ;
else cout << "YES" << endl ;
}
int main(){
int _ ; cin >> _ ;
while(_--) fyj() ;
return 0 ;
}
求极差最小
// n(2e5)个ai(1e9) // 求使极差最小的操作次数 ; // 每次可删第一个/最后一个元素
变向求最长相等子数组 ;
#include<bits/stdc++.h>
using namespace std ;
void fyj(){
int n ; cin >> n ;
vector<int> a(n) ;
for(int& x : a) cin >> x ;
int ans = 0 ;
// 子区间极差最小,最后极差一定是0 ;
// 也就是求最长相等子数组的长度
for(int i=0;i<n;i++){
int j = i ;
while(j<n && a[j]==a[i]) j++ ;
ans = max(ans,j-i) ;
i = j - 1 ;
}
cout << n - ans << endl ;
}
int main(){
int _ ; cin >> _ ;
while(_--) fyj() ;
return 0 ;
}
#软件开发笔面经#
查看4道真题和解析