ZOJ1016-Parencodings
来源:互联网 发布:java多线程运行机制 编辑:程序博客网 时间:2024/05/19 12:27
#include <stdio.h>int main(){ int t; int p[25]; int pair[25]; p[0] = 0; char s[45]; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int i; for (i = 1; i <= n; i++) { scanf("%d", &p[i]); } int j = 1, k; int cp; for (i = 1; i <= n; i++) { cp = p[i] - p[i - 1]; for (k = 1; k <= cp; k++) { s[j++] = '('; } s[j++] = ')'; } s[j] = '\0'; n *= 2; j = 1; for (i = 1; i <= n; i++) { if (s[i] == '(') { pair[j++] = i; } else { printf("%d", (i - pair[j-1] + 1) / 2); j--; if (i != n) { printf(" "); } } } printf("\n"); } return 0;}p序列纪录了右括号前左括号的个数,w序列纪录了右括号向左数遇到和它相匹配的左括号时遇到的左括号数。题目要求将p序列转化为w序列。按照p序列写出相应的字符串s,遍历s即可。
0 0
- zoj1016 Parencodings
- ZOJ1016 Parencodings
- zoj1016-Parencodings
- ZOJ1016-Parencodings
- zoj1016 Parencodings(括号匹配变形:STL栈处理+模拟)
- ZOJ1016
- zoj1016
- ZOJ1016
- zoj1016
- Parencodings
- Parencodings
- Parencodings
- :Parencodings
- Parencodings
- Parencodings
- Parencodings
- Parencodings
- Parencodings
- JSON序列化与反序列
- 【解题报告】传球游戏
- ELK
- 如果在docker中部署tomcat,并且部署java应用程序
- Collada学习笔记
- ZOJ1016-Parencodings
- ionicAPP发布问题
- 数据库SQL优化大总结
- 查看计算机安装的所有驱动文件
- 安卓图片下载
- git学习笔记(三)
- 字符串匹配的KMP算法
- Linux centos下安装jdk、maven、ant
- 平衡二叉树---Balanced Binary Tree