SGU179 Brackets light
179. Brackets light
memory limit per test: 131072 KB
output: standard
Your task is to find next (in lexicographic order) correct brackets sequence with the same length. You may assume that '(' < ')'.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; char s[];
int len, cnt;
bool flag = false; void update()
{
for (int i = len; i >= ; i--)
if (s[i] > s[i - ])
{
swap(s[i], s[i - ]);
reverse(s + i + , s + len + );
break;
}
} bool check()
{
cnt = ;
for (int i = ; i <= len; i++)
{
if (s[i] == '(')
cnt++;
else
{
if (cnt == )
return false;
else
cnt--;
}
}
if (cnt)
return false;
return true;
} int main()
{
while (scanf("%s", s + ) != EOF)
{
len = strlen(s + );
flag = false;
for (int i = ; i <= len; i++)
if (s[i] == '(' && s[i + ] != ')')
{
flag = true;
break;
}
if (!flag)
puts("No solution");
else
{
while ()
{
update();
if (check())
break;
}
for (int i = ; i <= len; i++)
printf("%c", s[i]);
printf("\n");
}
} return ;
}
SGU179 Brackets light的更多相关文章
- SGU 179 Brackets light(生成字典序的下一个序列)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=179 解题报告:输入一个合法的括号串,求出这个括号串的字典序的下一个串.(认为'(' ...
- SGU 179.Brackets light
时间限制:0.25s 空间限制:12M 题意 给定一个合法的仅由'(',')'组成的括号序列,求它的下一个合法排列.假定'('<')'. Solution: ...
- vs code 插件收集
名称 简述 Auto Close Tag 自动闭合HTML标签 Auto Import Typescript自动import提示 Auto Rename Tag 修改HTML标签时,自动修改匹配的标签 ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- vscode python开发插件推荐
vscode作为一款好用的轻量级代码编辑器,不仅支持代码调试,而且还有丰富的插件库,可以说是免费好用,对于初学者来说用来写写python是再合适不过了.下面就推荐几款个人觉得还不错的插件,希望可以帮助 ...
- 工具 - VS Code
杂项 1. 主题 brackets light pro, One Monokai theme 2. directory tree indent guidelines, directory vertic ...
- 【代码编译器】vscode 配置详细介绍
前言:运行环境.net6.0 C#10 安装.NET Core SDK和运行 官网下载地址:https://www.microsoft.com/net/download/core 安装.Net 4.7 ...
- LED Decorative Light Supplier - LED Environmental Decorative Lighting Application
Creating ambient lighting in the home can bridge the gap between the internal world and the outside ...
- LED Decorative Light Supplier - LED Neon Application: 5 Advantages
In the past 100 years, lighting has gone a long way. LED decorative lighting is now designed to meet ...
随机推荐
- python-redis集合模式
无序集合SADD set集合是直接去重的,只会输出 xiao hehe sadd names3 xiao xiao hehe hehe 获取集合 names3的所有值,集合不能用切片形式获取值, ...
- shell基础 -- grep、sed、awk命令简介
在 shell 编程中,常需要处理文本,这里介绍几个文本处理命令. 一.grep 命令 grep 命令由来已久,用 grep 命令来查找 文本十分方便.在 POSIX 系统上,grep 可以在两种正则 ...
- js 零零散散的总结。
Array.slice.call(arguments);可以将一个类数组转化为数组. Array.from() ,[...arr];也可以将一个类数组转化为数组(es6). (function() { ...
- 一个网页从输入URL到页面加载完的过程
过程概述 1.浏览器查找域名对应的IP地址 2.浏览器根据IP地址与服务器建立socket连接 3.浏览器与服务器通信:浏览器请求,服务器处理请求和响应 4.浏览器与服务器断开连接 具体过程 1.搜索 ...
- Live Archive 训练题 2019/3/9
7454 Parentheses A bracket is a punctuation mark, which is used in matched pairs, usually used withi ...
- Scrum立会报告+燃尽图(十月十七日总第八次)
本次作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246 一.小组介绍 组名:杨老师粉丝群 组长:乔静玉 组员:吴奕瑶.公 ...
- 字典树---2001 POJ Shortest Prefixes(找最短前缀)
做的第一道字典树的题,算比较水的: -->>>:传送门 代码: #include <stdio.h> #include<stdlib.h> #define M ...
- Windows Forms编程实战学习:第一章 初识Windows Forms
初识Windows Forms 1,用C#编程 using System.Windows.Forms; [assembly: System.Reflection.AssemblyVersion(& ...
- WPF和Expression Blend开发实例:Adorner(装饰器)应用实例
装饰器-- 表示用于修饰 UIElement 的 FrameworkElement 的抽象类 简单来说就是,在不改变一个UIElement结构的情况下,将一个Visual对象加到它上面. 应用举例: ...
- Docker 安装与常用命令介绍
docker的镜像文件作用就是:提供container运行的文件系统层级关系(基于AUFS实现),所依赖的库文件.已经配置文件等等. 安装docker yum install -y docker 启动 ...