AtCoder - 2586 Insertion

原题地址
这道题卡了我一定时间,大致题意就是让我们补“(“ ,”)”
大概思路就是直接找“(”的个数,和“)”的个数就行
附上代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
//#include <string.h>
#include <bits/stdc++.h>
#define INF 999999999
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
bool vis[100000]={0};
int main()
{
    boost;
    int n;
    cin >>n;
    string s,w;
    cin >>s;
    int sum=0,num=0;
    for(int i=0;i<n;i++){
        if(s[i]=='('){
           sum++;
        }
        else {
            if(sum>0) sum--;
            else num++;
        }

    }
    for(int i=0;i<num;i++)
        cout<<"(";
        cout<<s;
    for(int i=0;i<sum;i++)
        cout<<")";
    cout<<endl;
    return 0;

}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 18:05
哈哈哈哈哈感觉朋友找工作的已经疯掉了,直接上图
码农索隆:真老板娘:“我嘞个去,这不我当年的套路吗
点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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