美团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;
}