美团8.22技术算法笔试

第一题第三题全a代码

/*input
3
3 1 1
*/
#include <bits×dc++.h>
using namespace std;
typedef long long ll;

inline ll read() {
    char c = getchar(); ll x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
int a[10];

int main(){
int n=read();
for(int i=0;i<n;i++) a[i]=read();
sort(a,a+n);
int num=0;
do{ num++; }while(next_permutation(a,a+n));
cout<<num<<endl;
do{
for(int i=0;i<n;i++){
cout<<a[i];
if(i==n-1) cout<<endl;
else cout<<' ';
}
}while(next_permutation(a,a+n));


return 0;
}

/*input
()()()(())
*/
#include <bits×dc++.h>
using namespace std;
typedef long long ll;

inline ll read() {
    char c = getchar(); ll x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
const ll mod=1e9+7;
int main(){
string s; cin>>s;
int len=s.length();
stack<int> sta;

for(int i=0;i<len;i++){
if(s[i]=='('){
sta.push(-1);
sta.push(1);
}
else{
ll cur=1;
while(sta.size()&&sta.top()!=-1){
cur=cur*sta.top()%mod;
sta.pop();
}
sta.pop();
sta.push(cur+1);
}
}
ll cur=1;
while(sta.size()&&sta.top()!=-1){
cur=cur*sta.top()%mod;
sta.pop();
}
cout<<cur<<endl;
return 0;
}

#算法工程师##美团##笔经#
全部评论

相关推荐

karis_aqa:和hr没关系,都是打工的
点赞 评论 收藏
分享
09-28 09:18
吉首大学 Java
离上岸不远了的牛油很...:同27,你写的专业技能那些是真熟练了吗,我感觉稍微问深一点我都要🐔
你找实习最大的坎坷是什么
点赞 评论 收藏
分享
11-13 10:17
门头沟学院 Java
昨天面美团,jvm,juc问的好深啊,感觉小林coding不太够喔,牛油们有没有什么推荐的八股网站嘛🕒&nbsp;岗位/面试时间👥&nbsp;面试题目🤔&nbsp;面试感受
明天不下雨了:小林Coding:https://xiaolincoding.com/ 全栈哥:https://www.pdai.tech/ Guide哥:https://javaguide.cn/ 秀哥:https://interviewguide.cn/ 沉默王二:https://javabetter.cn/home.html 磊哥:https://www.javacn.site/interview/basic/ 小傅哥:https://bugstack.cn/ 源码哥:https://doocs.github.io/source-code-hunter/#/ 各大厂的公众号技术文章和一些经典的书籍
面试太紧张了怎么办?
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务