#include <bits/stdc++.h>
using namespace std;
int n;
char a[26];
void dfs(int l, int r, int sum){
if (r>l || l>n){
return;
}
if (sum == n<<1){
puts (a);
cout << '\n';
return;
}
a[sum] = '(';
dfs (l+1, r, sum+1);
a[sum] = ')';
dfs (l, r+1, sum+1);
}
int main(){
while (cin >> n){
dfs (0, 0, 0);
}
return 0;
}
加了
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
沒加
AC了
請不要再使用Bit..標頭檔
函式庫的include是將該.h檔案程式全部移入到你的程式碼內,你那樣並沒有比較快
你加了那三行,請問你有符合使用他的規範嗎?請先瞭解程式碼的定義、用途、使用方法、限制,再去使用~
請不要再使用Bit..標頭檔
函式庫的include是將該.h檔案程式全部移入到你的程式碼內,你那樣並沒有比較快
你加了那三行,請問你有符合使用他的規範嗎?請先瞭解程式碼的定義、用途、使用方法、限制,再去使用~
了解,新手嘛,體諒一下
提醒不要再犯前人的錯誤www
你可以試試看透過Cmd到指定目錄,然後輸入gcc -E name.c看一下預處理的結果
提醒不要再犯前人的錯誤www
你可以試試看透過Cmd到指定目錄,然後輸入gcc -E name.c看一下預處理的結果
👍🏻
#include
using namespace std;
int n;
char a[26];void dfs(int l, int r, int sum){
if (r>l || l>n){
return;
}
if (sum == n<<1){
puts (a);
cout << '\n';
return;
}
a[sum] = '(';
dfs (l+1, r, sum+1);
a[sum] = ')';
dfs (l, r+1, sum+1);
}int main(){
while (cin >> n){
dfs (0, 0, 0);
}
return 0;
}加了
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
沒加
AC了
用了ios::sync_with_stdio(false);就不能再混用iostream與stdio的函式了,你cout跟puts都使用會出問題,兩個選一個吧
#include
using namespace std;
int n;
char a[26];void dfs(int l, int r, int sum){
if (r>l || l>n){
return;
}
if (sum == n<<1){
puts (a);
cout << '\n';
return;
}
a[sum] = '(';
dfs (l+1, r, sum+1);
a[sum] = ')';
dfs (l, r+1, sum+1);
}int main(){
while (cin >> n){
dfs (0, 0, 0);
}
return 0;
}加了
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
沒加
AC了
用了ios::sync_with_stdio(false);就不能再混用iostream與stdio的函式了,你cout跟puts都使用會出問題,兩個選一個吧
小的已查過它的功用,謝謝🙏