今晚招行笔试,编程题第二题
刚招行第二题,我在本地ide上可以输出答案,为什么在题目上提交答案符合度为0.。。
(今晚感觉好像不是很难,但好多Java题。。。)
最后第三大题简答题第三小题是不是构造一个哈希
代码:
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
void fun(vector<string>&res,string s,int n,int i){
if(i>=n){
res.push_back(s);
return;
}
for(int j=1;j<=(n-i);j++){ int tmp=j; string s1="";
while(tmp--){
s1+="(";
}
tmp=j;
while(tmp--){
s1+=")";
}
fun(res,s+s1,n,i+j);
}
}
int main(){ int n;
cin>>n;
vector<string>res;
string s;
fun(res,s,n,0);
string str="";
int i=res.size()-1;
for(;i>0;i--){
str=str+res[i]+",";
}
str+=res[i];
cout<<str<<endl;
}
这是本地ide一个例子
#笔试题目#

