Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
代码In Reply To:算法与证明 Posted by:cavatina2016 at 2020-08-01 01:14:00 #include <stdio.h> #include <cstring> #include <stdlib.h> #define MAX_N 2000 int n; char str[2001]; char stack[2001]; int stackcount; int calc2() { int res = 0; stackcount = 0; for (int i = 0; i < n; ++i) { if (str[i] == '{') { stack[stackcount++] = '{'; } else if (stackcount > 0) { stackcount--; } else { stack[stackcount++] = '{'; res++; } } if (stackcount > 0) { while (stackcount % 2) printf("..."); res += stackcount / 2; } return res; } int main() { for (int t = 1; ; ++t) { scanf_s("%s", str, 10000); if (str[0] == '-') break; n = strlen(str); while (n < 1 || n > MAX_N || n % 2) printf("..."); printf("%d. %d\n", t, calc2()); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator