题解 | #小欧的括号嵌套#

小欧的括号嵌套

https://www.nowcoder.com/practice/0b461d2b82834cb1881567744effb0c1

#include <iostream>
using namespace std;

int main() {
    int n, r;
    cin >> n >> r;
    for(int i = 1; i < r; i++){
        cout << '(';
    }
    for(int i = 1; i <= (n-r + 1); i++){
        cout << "()";
    }
    for(int i = 1; i < r; i++){
        cout << ')';
    }
}
// 64 位输出请用 printf("%lld")

构造, 想到构造形状为:((((()()()))))的输出, 那么中间的()个数即为1 + 需多余插入的个数

#悬赏#
全部评论

相关推荐

嘀哩咕噜说啥呢:27届,这简历,强的逆天,大厂实习随便冲,面经多少看点,hot100刷完,大厂随便挑了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务